In this article you will learn the use of VBA.Inputbox and Application.Inputbox in VBA. Input box is used to take the input from use on run time.
VBA.Inputbox:
To take the input form user we use the Inputbox or VBA.Inputbox. This input box looks like below image –

Below is the Code for VBA.Inputbox-
Sub VBA_Inputbox() Dim myinput As Variant myinput = VBA.InputBox("Input the value here", "VBA Input Box") MsgBox myinput End Sub
Application.Inputbox:
Application.input box is also used to take the input from user on run time. We can defined the Input type also in this input box. We can use 7 different types as given below-

This input box looks like below image

Below is the Code for Application.Inputbox with 7 different types-
Sub Inputbox_Type_0() Dim myinput As Variant myinput = Application.InputBox("Input the formula", "Input box type 0", Type:=0) MsgBox myinput End Sub Sub Inputbox_Type_1() Dim myinput As Variant myinput = Application.InputBox("Input the number", "Application Inputbox", Type:=1) MsgBox myinput End Sub Sub Inputbox_Type_2() Dim myinput As Variant myinput = Application.InputBox("Input the string", "Input box type 2", Type:=2) MsgBox myinput End Sub Sub Inputbox_Type_4() Dim myinput As Variant myinput = Application.InputBox("Input the True or False", "Input box type 4", Type:=4) MsgBox myinput End Sub Sub Inputbox_Type_8() Dim myinput As Range Set myinput = Application.InputBox("Select the range", "Input box type 8", Type:=8) MsgBox myinput.Address End Sub Sub Inputbox_Type_16() Dim myinput As Variant myinput = Application.InputBox("Please input the Error", "Input box type 16", Type:=16) Select Case myinput Case CVErr(xlErrNA) myinput = "#N/A error" Case CVErr(xlErrDiv0) myinput = "#DIV/0! error" Case CVErr(xlErrNull) myinput = "#Null!" Case CVErr(xlErrName) myinput = "#Name? error" Case CVErr(xlErrNum) myinput = "#Num! error" Case CVErr(xlErrRef) myinput = "#Ref! error" Case Else myinput = "This is not an error" End Select MsgBox myinput End Sub Sub Inputbox_Type_64() Dim myinput As Variant myinput = Application.InputBox("Please input the array like - {1,2,3}", "Input box type 64", Type:=64) Dim str As String Dim i As Integer For i = LBound(myinput) To UBound(myinput) str = str & myinput(i) & vbLf Next i MsgBox str End Sub