Decide what an InputBox is supposed to return

 2000-02-05    Dialogs    0    49

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 :

Sub DecideUserInput()
Dim bText As String, bNumber As Integer
    ' here is the InputBox-function :
    bText = InputBox("Insert in a text", "This accepts any input")
    ' here is the InputBox-method :
    bNumber = Application.InputBox("Insert a number", "This accepts numbers only", , , , , , 1)
    MsgBox "You have inserted :" & Chr(13) & _
        bText & Chr(13) & bNumber, , "Result from InputBox"
End Sub
The InputBox-method has a third argument, Type, that decides what the user is allowd to insert in the InputBox-dialog. Type can be one of the following :

Type: Accepted Input:
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

Leave a comment:

Your comment will only be published after it has been moderated and found spam free.
Your e-mail address will only be used to display your Gravatar.