Using InputBox Method in Excel VBA

You can recieve a simple information from user using Message Box in your Excel VBA code: Yes / No / Cancel etc.

But to gather more specific information (formula, number, text, logical value or cell reference) from a user you need Application.InputBox method:


where Type specifies the return data type:

Type Values
0 Formula
1 Number
2 Text (String)
4 Logical value (True or False)
8 Cell reference (Range object)
16 Error value
64 Array of values


Example: Using InputBox method in Excel

Sub TestInputBox()
    Dim myRange As Range
    Set myRange = Application.InputBox(Prompt:= _
        "Please Select a Range", _
        Title:="InputBox Method", Type:=8)
    If myRange Is Nothing Then
        ' Range is blank
    End If
End Sub


comments powered by Disqus