Locked lesson.
About this lesson
Working with the VBA InputBox to prompt the user to enter information and capture it for later use.
Exercise files
Download this lesson’s exercise file.
Collecting feedback from a VBA InputBox.xlsm25.4 KB
Quick reference
Collecting feedback from a VBA InputBox
Continuation of user feedback and input
When to use
To gather data that the user enters into a message box.
Instructions
InputBox Syntax
sAnswer = InputBox("Message", "Title", "Default Answer")
Syntax With a Select Case
- It is advisable to use a Select Case to review the input
Dim sAnswer As String
sAnswer = InputBox("Message", "Title", "Default Answer")
Select Case LCase(sAnswer)
Case Is = "one"
'Do something
Case Is = "two"
'Do something else
Case Else
'What did the user enter?
End Select
Hints & tips
- Don't forget to enclose the InputBox parameters (message, title, etc.) in parentheses.
- A default input can be set if needed.
- Text comparisons are case-sensitive, so using the LCase command will force the input to be lower case.
- Always include an Else in your Select Case statement in case the user enters something you didn't predict.
Login to download
Lesson notes are only available for subscribers.