logo ASAP Utilities

Excel tip: Decide what an INPUTBOX is supposed to return

Date: 5 september 2001

If you want to get any information from the user you can use the INPUTBOX-function. This function displays a dialogbox that lets the user fill inn anything and returns the content as a string.

Sometimes you want to decide what the user is supposed to fill in, instead of accepting any information. That's when you use the INPUTBOX-method.

The Application.Inputbox-method has a third argument, Type, that decides what the user is allowed to insert in the INPUTBOX-dialog. Type can be one of the following :

0     : A formula
1     : A number
2     : Text
4     : A logical value (True or False)
8     : A cell reference, e.g. a Range-object
16    : An error value, e.g. #N/A
64    : An array of values


Copy-paste friendly code:
Sub DecideUserInput()
' Example demonstrating the difference between then
' inputbox() and application.inputbox() fuctions
      Dim strText                            As String
      Dim lNumber                            As Long

      ' here is the INPUTBOX-function :
      strText = InputBox("Type your text", "This accepts any input")
      ' here is the APPLICATION.INPUTBOX-method :

      lNumber = Application.InputBox(prompt:="Insert a number", _
                                     Title:="This accepts numbers only", Type:=1)

      MsgBox "You have inserted:" & vbNewLine & _
             "text:" & Chr(9) & strText & vbNewLine & _
             "number:" & Chr(9) & lNumber, vbInformation, "Result from INPUT-boxes"
End Sub



« back

Home Privacy Policy Cookie Policy EULA Download All added Excel tools Sitemap Contact Us


Empowering Excel Users Worldwide for 25 Years