Input box
VBA

VBA.Inputbox Vs Application.Inputbox in Excel VBA

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 –

VBA.Inputbox
VBA.Inputbox

 

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-

Types for Application.Inputbox
Types for Application.Inputbox

 

This input box looks like below image

Application.Inputbox
Application.Inputbox

 

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

Click here to download this Excel workbook.

PK
My Name is PK. I am founder of PK-AnExcelExpert.com. I am a Microsoft Certified Professional. I have more than 10 years of experience in Data Visualization, Excel Automation and dashboard creation. Excel is my passion and I like to do always something innovative in Excel and share it with other people.
https://www.pk-anexcelexpert.com