Home>Blogs>VBA>VBA.Inputbox Vs Application.Inputbox in Excel VBA
Input box
VBA

VBA.Inputbox Vs Application.Inputbox in Excel VBA

In this article you will learn the use of VBA.Inputbox Vs Application.Inputbox in VBA. Input box is used to take the input from use on run time.

VBA.Inputbox Vs Application

To take the input form user we use the VBA.Inputbox Vs Application. This input box looks like below image –

VBA.Inputbox Vs Application
VBA.Inputbox Vs Application

 

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.

 

Visit our YouTube channel to learn step-by-step video tutorials

Youtube.com/@PKAnExcelExpert

 

 

PK
Meet PK, the founder of PK-AnExcelExpert.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your Excel skills to the next level!
https://www.pk-anexcelexpert.com