Method Application.InputBox with VBA in Microsoft Excel

The return value of the Application.InputBox () method depends on the selected type. As a type you can e.g. B. Select number, formula, cell reference, text or truth value. If the user clicks the Cancel button, False is returned; you can use this for further process control.

A notice: Versions of Excel prior to Excel 2007 are not stable when this method is called. After calling the method, you occasionally log out completely without offering the user an input option.

As with the simple input field, you could specify a default value and a title. The type of the InputBox is determined with the last parameter, therefore named parameters are used in the examples.

An example of entering a number (type 1):


Sub EingabeZahl()
ThisWorkbook.Worksheets("Tabelle1").Activate
Range("A1").Value = Application.InputBox _
(Prompt:="Zahl:", Type:=1)
End Sub

If the user makes a valid entry, this is output in the present example in cell A1. Valid numbers are e.g. B. 5,7 or 5e2 (= 5 times 102 = 500) or 0.57. Invalid numbers are e.g. B. 5a7 or a57. The entry of 5.7 is valid and results in July 5th of the current year. Validity If the user does not make a valid entry, he will be made aware of this.

An example of entering a formula (type 0):


Sub EingabeFormel()
ThisWorkbook.Worksheets("Tabelle1").Activate
Range("A1").Value = Application.InputBox _
(Prompt:="Formel:", Type:=0)
End Sub

The user has the option of entering formulas with cell references. These can also include non-contiguous areas. If you enter = SUM (B1: B3), this formula becomes the content of cell A1 and the expected calculation result is output in cell A1. If the user begins his entry with = SUM (then he can also select the cell reference to be summed up with the mouse or the arrow keys. Then he only has to close the brackets. An invalid formula leads, as expected, to an error message being output in the target cell ( #WERT? Or #NAME?).

An example of entering a cell range (type 8):


Sub EingabeZellbereich()
Dim RG As Range
ThisWorkbook.Worksheets("Tabelle1").Activate
Set RG = Application.InputBox _
(Prompt:="Zellbereich:", Type:=8)
RG.Borders.LineStyle = xlContinuous
End Sub

First an object variable is declared for a range. The user has the option of entering cell ranges using both the keyboard and the mouse. The cell areas can also include discontinuous areas.

Was the explanation to "Method Application.InputBox with VBA in Microsoft Excel"Helpful? Rate now:

Weitere Erklärungen zu Skriptsprachen