Live-Forum - Die aktuellen Beiträge
Datum
Titel
18.04.2024 18:04:29
18.04.2024 16:33:24
Anzeige
Archiv - Navigation
268to272
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
268to272
268to272
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Inputbox: Bei Leereingabe frage wiederholen

Inputbox: Bei Leereingabe frage wiederholen
18.06.2003 10:40:15
stephan
Hallo,

wenn ich in folgendem Programm einfach nur return drücke, wird das Programm verlassen. Ich möchte das wenn man nur return drückt die Frage wiederholt wird.

Dim d
wiederholen:
d = InputBox("Wie viele direkte Mitarbeiter sind in der gesamten Produktion beschäftigt ?")
If VBA.IsNumeric(d) Then
If VBA.CInt(d) > 0 And VBA.CInt(d) < 10000 Then
Worksheets("Druckblatt").Range("MA") = d
Else
MsgBox ("Die Zahl muß zwischen 1 und 10.000 liegen. Bitte wiederholen Sie Ihre Eingabe.")
GoTo wiederholen
End If
Else
If d = vbcanel Then
Sheets("Auswahl").Activate
Exit Sub
End If
MsgBox ("Das war keine Zahl")
GoTo wiederholen
End If

Vielen Dank im voraus

11
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
Re: Inputbox: Bei Leereingabe frage wiederholen
18.06.2003 10:49:07
Nike
Hi,

Dim d
wiederholen:

'mit do loop
do
d = InputBox("Wie viele direkte Mitarbeiter sind in der gesamten Produktion beschäftigt ?")
loop until d <> ""

'oder mit if then
if d = "" then
GoTo wiederholen
end if
If VBA.IsNumeric(d) Then
If VBA.CInt(d) > 0 And VBA.CInt(d) < 10000 Then
Worksheets("Druckblatt").Range("MA") = d
Else
MsgBox ("Die Zahl muß zwischen 1 und 10.000 liegen. Bitte wiederholen Sie Ihre Eingabe.")
GoTo wiederholen
End If
Else
If d = vbcanel Then
Sheets("Auswahl").Activate
Exit Sub
End If
MsgBox ("Das war keine Zahl")
GoTo wiederholen
End If

Bye

Nike

Anzeige
Re: Inputbox: Bei Leereingabe frage wiederholen
18.06.2003 11:01:37
stephan
Hallo nike,

wenn ich es so mache funktioniert leider die Schaltfläche "abbrechen" nicht mehr. Diese soll aber weiterhin funktionieren.

Re: Inputbox: Bei Leereingabe frage wiederholen
18.06.2003 11:06:50
Nike
Hi,
if d = false then exit sub

damit könntest du dann ganz abbrechen...

Bye

Nike

Habe noch nie Nike widersprochen, aber...
18.06.2003 11:14:21
Andreas Walter
bist du da sicher?

a = InputBox("frage")
MsgBox a

bringt bei mir eine leere zeichenkette (und nicht false), wenn ich abbrechen betätige.

Finde keine Möglichkeit zu unterscheiden, zwischen leer Eingabe und Abbrechen

Vielleicht hilft ein Defaultwert
Dann bekommt man "" zurück, wenn abbrechen betätigt wurde, was eine Indiz ist dafür, dass der Anwender abbrechen wollte. 'Eingabe' schickt den Defaultwert zurück

Anzeige
Re: Habe noch nie Nike widersprochen, aber...
18.06.2003 11:21:33
stephan
Genau das was walter schreibt ist mein Problem.
Re: Habe noch nie Nike widersprochen, aber...
18.06.2003 11:24:59
Andreas Walter
Wie wäre es, wenn ein "" zurückkommt, eine MSGBOX mit dem Text
"Mögst hier raus" und Knöpfe "Yo" und "Nee" einzublenden. Nur bei "Yo" kommt man raus - bei "Nee" zurück zum INPUTBOX

Ansonsten - I see black

Re: Habe noch nie Nike widersprochen, aber...
18.06.2003 11:32:27
Nepumuk
Hallo Srephan,
vesuch es mal so:

Option Explicit
Public Sub test()
Dim Antwort As Variant
Do
Antwort = Application.InputBox("Wie viele direkte Mitarbeiter sind in der gesamten Produktion beschäftigt ?", "Eingabe", Type:=1)
If CStr(Antwort) <> "0" And Antwort = False Then Sheets("Auswahl").Activate: Exit Sub
If Int(Antwort) <> Antwort Then
MsgBox "Nur ganze Zahlen erlaubt.", 48, "Hinweis"
Else
If Antwort <= 0 Or Antwort >= 10000 Then
MsgBox "Nur Werte zwischen 0 und 10000 erlaubt.", 48, "Hinweis"
Else
Worksheets("Druckblatt").Range("MA") = Antwort
Exit Do
End If
End If
Loop
End Sub

Code eingefügt mit: Excel Code Jeanie
Gruß
Nepumuk

Anzeige
Deswegen bin ich hier...
18.06.2003 11:41:39
Andreas Walter
um neues zu lernen. Danke Nepumuk. Verstehe ich aber nicht ganz
inputbox hat kein type Möglichkeit
application.inputbox schon.

Wenn braucht/benötigt/benutzt man
a) nur den Namen der Funktion
b) application. und danach den Namen der Funktion
Was ist der Grund für diese zwei ähnlich aber anscheinend unterschiedliche Möglichkeiten

Danke im voraus

Re: Deswegen bin ich hier...
18.06.2003 12:15:35
Nepumuk
Hallo Andreas,
warum es zwei unterschiedliche InputBoxes gibt, da musst du Bill fragen. Ich benutze eigentlich nur die Application.InputBox da sie mir die Möglichkeit bietet die Eingabe ohne Prüfung zuzulassen. Denn, wenn ich z.B. den Type auf 1 stelle sind halt nur nummerische Eingaben möglich.
Gruß
Nepumuk
Anzeige
Re: Kein aber ;-) ok doch doch immer her damit ;-)
18.06.2003 12:30:52
Nike
Hi,

sorry, das ich mich jetzt erst melden (kann)
bin leider noch so nebenher beschäftigt ;-)

Also, nur mit
a = InputBox("frage")
MsgBox a

bekomme ich auch ne leere Zeichenkette...

Mach ich aber das hier:

dim a as Range
set a = Application.InputBox(prompt:="Zellauswahl", Title:="Zellauswahl", Type:=8)

Ergibt Abbrechen dann false...

Damit hättest du dann auch deine Möglichkeit zur Unterscheidung...
Inputbox und Application.Inputbox
sind halt zwei verschiedene Paar Schuh ;-)

Bye

Nike

P.S. Du kannst mir jederzeit Widersprechen,
ich hab die Weisheit ja auch nicht Löffelweise intus ;-)

Anzeige
Google findet...
18.06.2003 14:45:39
Andreas Walter
u.a. folgendes

What's the difference between the InputBox Function and Method?
Keywords: Input Range Input Box User Input
Posted May 16, 1996

The InputBox function is provided by VBA for getting text from a user. It always returns text. The InputBox method is provided by Excel and can return text, numbers, arrays and/or references-in other words, the Excel-specific data types. Here's an example:

Sub TestInputBoxes()
''' Test InputBox Function
MsgBox InputBox(prompt:="Type a short sentence below.", _
Title:="What you type below will display in Message Box")

''' Test InputBox Method (restricts input to a number)
MsgBox Application.InputBox(prompt:="This will only accept a number.", _
Title:="Testing InputBox method", Type:=1)
End Sub

The InputBox Method requires the Application object (because it comes from the application Excel rather than VBA).

The Type argument can limit the input from your user to a specific type. For example, a type 8 allows you to drag a range and get a range object for your routines. See the on-line help for additional types and other optional arguments.


EXCEL SPECIFIC INPUT BOX
You're probably familiar with VBA's InputBox statement, as it is available to all Office applications. The Excel library offers its own version of this statement, Application.InputBox. Use the Excel-specific version when inputting formulas and ranges.

This statement takes the form:

Application.InputBox(prompt, [title], [default], [left], [top], [helpfile], [helpcontextID], [type])

Only the first argument, Prompt, is required. The type argument specifies whether the input box expects a formula (0), number (0), range (8), or matrix of cells (64). For example, the following statement would display an input box that accepts only a valid range address:

Application.InputBox ("Please enter the range address",Type:=8)

by Susan Sales Harkins

UserVal = Application.InputBox("Value?", , , , , , , 1)
If UserVal <> False Then Range("A1") = UserVal
VBA has an InputBox function, and there's also an InputBox method for the Application object. Are these the same?

No. Excel's InputBox method is more versatile since it allows validation of the user's entry. The preceding example uses 1 (which represents a numeric value) for the last argument of the InputBox method. This ensures that the user enters a value into the input box.


InputBox

The InputBox function creates and displays a simple dialog box containing a prompt, an edit box, and OK and Cancel buttons. If you require a more elaborate dialog box, you must create a custom dialog box using a dialog sheet (see later). The return value from the InputBox function is the string entered by the user. If the input box is empty, or if the user pressed Cancel the return value is an empty string. The following displays a simple input box:

radius=InputBox("Enter the circle radius:", "Circle Radius")

The InputBox method of the Application object is similar but allows you to specify the desired data type for the data entry (a range, or a string for example). If the user enters data with an incorrect type, Excel displays a message indicating this.

If a data type is specified, the return value from the InputBox method has that data type if the user pressed Enter or OK. If the data type is not specified the return value is a string. In either case, the return value is False if the user pressed Cancel or Esc to cancel the dialog box. The full syntax includes the facility to specify the screen location of the input box and context-sensitive help (see the Help file) but the main parameters are:

result=Application.InputBox(Prompt:="....", Type:=n)

The value of n may be one of the following:

0 Formula
1 Number
2 String
4 Logical
8 Range
16 Error
64 Array of values

The following code uses the InputBox method to ask the user for a search range and a search value. the search range must be a valid Range reference and the search value must be a number.

Sub CountValues()
cellCount=0
Set rangeToSearch = Application.InputBox(Prompt:="Enter the range to search", type:=8) ‘type=8 - must be a range object
searchValue = Application.InputBox(Prompt:="Enter the search value", Type:=1) ‘type=1 - must be a number
If searchValue=False then Exit Sub ‘user clicked Cancel
For Each c in rangeToSearch
If c.Value=searchValue then cellCount=cellCount+1
Next
MsgBox cellCount
End Sub

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige