VBA Function: InputBox

The VBA InputBox function displays a dialog box that prompts the user to enter text and returns the entered value.

Usage:

InputBox(prompt)

or

InputBox(prompt, title, default_response)


Example of Usage

Asking the user for their first name using the dialog box:

Sub example()
    
    firstName = InputBox("Enter your first name:", "User")
    
    'If a value was entered and the user clicked OK
    If firstName <> "" Then
        MsgBox firstName 'Returns the entered first name
    End If
    
End Sub
excel vba inputbox function