Name
[Application.]InputBox(Prompt
, [Title
], [Default
], [Left
], [Top
], [HelpFile
], [HelpContextID
], [Type
])
Synopsis
This is the same as the Visual Basic InputBox
method with one addition: Application.InputBox
allows you to get a selected range using the Type
argument which accepts the settings in the following table:
Setting |
Input is |
---|---|
0 |
A formula |
1 |
A number |
2 |
Text (a string) |
4 |
A logical value (True or False) |
8 |
A cell reference, as a |
16 |
An error value, such as #N/A |
64 |
An array of values |
The following code demonstrates getting a range using InputBox
:
Sub TestInputBox( ) Dim rng As Range On Error Resume Next Set rng = Application.InputBox( _ "Select a cell", , , , , , , 8) If Not (rng Is Nothing) Then Debug.Print rng.Count & " cells selected." Else Debug.Print "Input cancelled." End If End Sub
See Chapter 3 for details on the Visual Basic InputBox
method.
Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.