VBA’s basic InputBox accepts a prompt and returns what the user types as text; it does not provide a built-in drop-down list of choices. In Excel, use Application.InputBox when you need to restrict the kind of input, or show a numbered menu and validate the response when you need named options.
What “options” means in a VBA InputBox
The phrase “InputBox options” can refer to two different things: the arguments that control the dialog, or the choices a user can select. The standard VBA InputBox function has arguments for the prompt, title, default value, position, and optional help information. Those arguments change how the dialog looks and behaves, but they do not add radio buttons, a drop-down, or custom buttons.
Excel’s Application.InputBox adds a useful Type argument. It can require a number, text, a formula, a logical value, or a range reference, among other input types. It still is not a control for presenting a list such as “Red, Green, Blue.” For a short list, put the choices in the prompt and validate the reply. For a polished selection interface, use a UserForm.
That distinction helps avoid a common misconception: setting Type:=2 does not create two choices. The number 2 means that the response should be text.
Basic InputBox arguments
The standard function is available in VBA and returns a String. Its optional arguments let you provide a title, a starting value, and a position for the dialog. If you include a help file, you can also supply a help context. Leaving optional arguments out is usually simplest; provide a useful prompt and title so the user understands what is being requested.
For example, a prompt can ask for a department name and the title can read “Department.” A default value can be useful when most users will accept the same value, but it should not imply that an unconfirmed value has already been selected. The position arguments use twips, an older screen-measurement unit, so many macros are clearer and easier to maintain when they leave the dialog at its default position.
One limitation matters when handling cancellation: the standard function returns an empty string both when the user clicks Cancel and when the user submits a blank response. If those actions need different meanings, use a different interface or design the prompt so a blank response is acceptable or can be treated as invalid.
Restrict input with Application.InputBox
In Excel VBA, Application.InputBox displays an Excel input dialog and lets you set the expected return type. The Type argument accepts these values:
0: a formula.1: a number.2: text.4: a logical value, such as TRUE or FALSE.8: a cell reference returned as a Range object.16: an error value.64: an array of values.
You can add type values to allow more than one kind of response. For example, Type:=3 combines 1 and 2, permitting a number or text. These settings validate the data category, not its business meaning: a numeric type does not by itself ensure that a value is positive, within a range, or appropriate for a particular worksheet.
Unlike the standard function, Application.InputBox returns Boolean False when the user cancels. Store its result in a Variant so the macro can distinguish that Boolean from ordinary text. If accepting the literal word “False” as a text response is possible, checking the result’s type is especially important.
Offer a short list of named choices
For a small number of fixed options, a numbered prompt is straightforward and works without a UserForm. The macro below asks for one of three actions, rejects anything else, and separately detects Cancel. Since it uses a text input type, users can enter the displayed number or the corresponding word.
Save a copy of the workbook before running a macro. VBA changes cannot be reversed with Ctrl+Z, and a macro may alter workbook data.
Sub ChooseReportAction()
Dim response As Variant
Dim choice As String
Do
response = Application.InputBox( _
Prompt:="Choose an action: 1 = Summary, 2 = Detail, 3 = Cancel", _
Title:="Report options", _
Type:=2)
' Application.InputBox returns Boolean False when Cancel is clicked.
If VarType(response) = vbBoolean Then Exit Sub
choice = UCase$(Trim$(CStr(response)))
Select Case choice
Case "1", "SUMMARY"
MsgBox "Summary selected."
Exit Sub
Case "2", "DETAIL"
MsgBox "Detail selected."
Exit Sub
Case "3", "CANCEL"
Exit Sub
Case Else
MsgBox "Enter 1, 2, or 3, or use the displayed action name."
End Select
Loop
End Sub
This approach is appropriate when the options are few and stable. If the choices are long, frequently updated, or easy to confuse, a typed response creates avoidable errors. In that case, a list control is usually a better fit.
Validate the answer, not just its type
An input type checks only a broad category. If a prompt asks for a quantity from 1 to 20, Type:=1 accepts numbers outside that range too. The macro should apply its own rules after confirming that the user did not cancel. Validation may check a minimum and maximum, whether the value is whole, whether text matches an approved label, or whether a selected range is on the intended sheet.
For menu text, trimming spaces and comparing without regard to letter case makes entry more forgiving. The example uses Trim$ and UCase$ for that reason. For numeric input, conversion should be deliberate: check the value and its permitted range before using it to change cells or perform calculations. Avoid assuming that a value is safe simply because Excel accepted it as a number.
Also decide what blank input means. A blank response might be a valid choice, an instruction to use a default, or an error that should prompt again. State that rule in the prompt or handle it explicitly in code; otherwise users may not know whether the dialog accepted their action.
Ask users to select a worksheet range
When a user needs to point to cells rather than type an address, use Application.InputBox with Type:=8. The returned value is a Range object, so it must be assigned with Set. Cancellation needs care because the cancel result is not a Range; the example suppresses the assignment error and checks whether a range was set.
Sub AskForRange()
Dim selectedRange As Range
' Save a copy before running macros that may change workbook data.
On Error Resume Next
Set selectedRange = Application.InputBox( _
Prompt:="Select the cells to use", _
Title:="Choose a range", _
Type:=8)
On Error GoTo 0
If selectedRange Is Nothing Then
MsgBox "No range was selected."
Exit Sub
End If
MsgBox "Selected range: " & selectedRange.Address
End Sub
After a range is selected, check that it meets the macro’s needs. For example, confirm that it is on the expected worksheet, has the expected number of columns, or does not include a header row if the procedure expects data only. A valid Range object is not automatically the correct range for the task.
When to use a UserForm or MsgBox instead
A numbered InputBox is quick to build, but users must remember or read the option labels and type a response. A UserForm is more appropriate when the interface needs a ComboBox, ListBox, radio buttons, explanatory text, or several related inputs. It also lets you control which combinations are allowed before the user submits the form. The trade-off is more setup and code than a one-line dialog.
MsgBox is useful for a small, fixed decision such as Yes or No. Its buttons are built-in button sets, and VBA returns constants such as vbYes or vbNo so the macro can branch on the answer. It is not a general replacement for a custom choice list: you cannot rename its standard buttons to arbitrary labels such as “Import” and “Review.”
In short, use a basic InputBox for a simple text response, Application.InputBox for type-aware input or range selection, a numbered prompt for a short menu, MsgBox for a standard confirmation, and a UserForm for a more guided interface.
Common problems and practical safeguards
- Cancel is mistaken for blank. The standard function returns an empty string for both. Use a design that does not need to distinguish them, or use a suitable alternative.
- The wrong InputBox is used.
InputBoxandApplication.InputBoxhave different behavior and return handling. Use the Excel method when you need its Type setting. - A range result is assigned without Set. A Type 8 response is an object reference. Assign it to a Range variable using
Setand handle cancellation. - Input is accepted without a second check. Data type is not the same as a valid business value. Add rules for allowed names, limits, and worksheet context.
- The prompt is unclear. Say what format to enter, show the available choices, and explain what Cancel does. Avoid relying on users to infer whether a blank means “skip” or “use default.”
Macros also depend on workbook macro settings and the user’s security policy. Do not ask users to enable code from an untrusted file simply to use an input dialog. If a workbook will be shared, document what the macro changes and test the cancellation and invalid-entry paths as well as the successful path.
Frequently Asked Questions
Can a VBA InputBox show a drop-down list?
No. Neither the standard VBA InputBox nor Excel’s Application.InputBox creates a drop-down. Use a UserForm with a ComboBox or ListBox, or show a short numbered menu and validate the response.
How do I detect Cancel in an Excel InputBox?
With Application.InputBox, assign the result to a Variant and check whether it is Boolean False before converting or using it. The standard VBA InputBox returns an empty string for Cancel, which is indistinguishable from submitting no text.
What does Type:=1 mean in Application.InputBox?
It requests a numeric response. It does not impose a minimum, maximum, or integer-only rule, so add separate validation when those restrictions matter.
How do I make an InputBox accept only a range?
Call Excel’s Application.InputBox with Type:=8 and assign the result to a Range object using Set. Handle Cancel, then verify that the selected cells are suitable for the task.
Can I change the buttons on an InputBox?
No. The InputBox dialogs do not offer arbitrary custom button labels. Use a UserForm for named actions, or use MsgBox when a built-in Yes/No or other standard button set is sufficient.
Related
- Excel Shortcut Keys: Essential Windows and Mac Keys
- Multi-Level Dropdown List in Excel: How to Create One
- Excel Insert Page Breaks: Steps, Options, and Fixes
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA: List All Sheets in a WorkbookTo list every sheet in the workbook that contains your VBA code, loop through its Sheets collection and…
- Excel VBA: Set a PivotTable Filter ValueTo set a PivotTable report filter with VBA, get the PivotField and assign its item to CurrentPage: for…
- Excel VBA: Find Unique Values in a ColumnTo find unique values in an Excel column with VBA, loop through the source cells, keep the first…
- Excel Number to Words: Formula, VBA, and How to Use ItExcel has no built-in English worksheet formula that converts an ordinary number into words. In Microsoft 365 for…
- VBA Error Handling in Loops: Safe Patterns That WorkIn VBA, use an error handler to decide what a loop should do when one item fails: log…
- Using MsgBox in VBA: Syntax, Buttons, and Return ValuesIn Excel VBA, use MsgBox to show a pop-up message or ask a user a simple question. Call…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.