VBA InputBox Default: How to Set It and Handle Cancel

VBA & macros · Updated November 18, 2026

In VBA, set an InputBox default by supplying the third argument: InputBox(prompt, title, default). That value appears in the text field when the dialog opens; if you omit it, the field starts empty. The built-in VBA function returns an empty string both when the user cancels and when they submit a blank response, so that distinction matters when you design the prompt.

What the default argument does

The VBA InputBox function displays a simple dialog with a prompt, an optional title, a text field, and OK and Cancel buttons. Its optional third argument, named Default, supplies the initial text in that field. It is a starting value, not a value VBA automatically accepts: the user can edit it, replace it, or clear it before choosing OK.

The function’s argument order is important. The prompt is required, while the title comes second and the default comes third. To set a default but keep a custom title, provide both the title and default. Leaving out the title and putting a value in the second position does not set the default; it sets the dialog title.

InputBox(prompt[, title][, default][, xpos][, ypos][, helpfile, context])

The square brackets in this syntax indicate optional arguments; they are not characters to type into VBA. The later position and help arguments are rarely needed for an ordinary prompt. Because arguments are positional, you cannot skip the title and then supply the default as the second argument.

Set a default with a simple example

This complete macro asks for a department name and starts the text field with “Sales.” Save a copy of the workbook before running a macro: macro actions are not undone with Ctrl+Z. In Excel for Microsoft 365 on Windows, you can put the code in a standard module in the Visual Basic Editor, opened with Alt+F11.

Sub AskForDepartment()
    ' Ask for a department, starting with a useful suggestion.
    Dim department As String

    department = InputBox("Enter a department name:", _
                          "Department", "Sales")

    If Len(department) = 0 Then
        MsgBox "No department was entered."
    Else
        MsgBox "Selected department: " & department
    End If
End Sub

When the dialog opens, the text field contains Sales. If the user types “Support” and selects OK, the function returns “Support.” If they leave “Sales” unchanged and select OK, it returns “Sales.” If they erase the text and select OK, the result is an empty string. That last case is not the same as accepting the suggested value.

The default can be a literal string, as above, or an expression that evaluates to text. For example, InputBox("Enter a note:", "Note", "Check totals") supplies a fixed suggestion. The third argument is an initial entry, not a placeholder or hint that disappears automatically when the user begins typing.

Choose a default that helps rather than misleads

A good default represents the most likely useful answer without quietly deciding something the user should choose. It can save keystrokes, but an inappropriate prefilled value can lead to accidental acceptance. Think about the task, the user’s likely next action, and the cost of accepting the suggestion unchanged.

  • Use a frequent, safe value. A current reporting year or a commonly used category can be a reasonable starting point if users can easily change it.
  • Make the prompt and default agree. If the prompt asks for a short code, do not prefill a full description that will be stored in the code field.
  • Avoid implying that a value was verified. A suggested customer number is not proof that it belongs to the intended customer.
  • Keep dates unambiguous. A text entry such as 2026-11-02 is less likely to be mistaken for a different day and month than a locale-dependent date string.
  • Consider whether a blank answer is meaningful. If blank is allowed, explain that in the prompt; if it is not, check the returned value before using it.

For an ordinary text prompt, the default is just text. VBA does not automatically validate that a value is a date, number, existing worksheet name, or member of a list. A user can replace the suggestion with anything the dialog accepts, so validation belongs in your code when the input has rules.

Use a variable or a calculated default

You can build the default at run time. For example, a macro might suggest the current year, a value already stored in a cell, or the name of the active worksheet. Convert non-text values to text deliberately so the dialog gets a clear string rather than relying on an implicit conversion.

This example formats today’s date as year-month-day before displaying it. Save a copy of the workbook before running it, particularly if you extend the example to change cells after the user responds.

Sub AskForReportDate()
    ' Suggest today's date in an unambiguous text format.
    Dim suggestedDate As String
    Dim response As String

    suggestedDate = Format$(Date, "yyyy-mm-dd")
    response = InputBox("Enter the report date:", _
                        "Report date", suggestedDate)

    If Len(response) = 0 Then
        MsgBox "No date was entered."
    ElseIf IsDate(response) Then
        MsgBox "VBA recognizes this as a date."
    Else
        MsgBox "Enter a date VBA can recognize."
    End If
End Sub

IsDate checks whether VBA recognizes the response as a date, but accepted date formats can depend on regional settings. If a workbook must interpret dates consistently across computers, define the allowed format and parse it accordingly rather than assuming that every user’s locale reads a date string the same way.

For a value taken from a worksheet cell, a simple approach is to assign the cell’s displayed or stored value to a declared variable, convert it to text when appropriate, and pass that variable as the third argument. Check for empty cells and error values first: a cell containing an Excel error is not a useful text default.

Blank responses and Cancel are different situations

A common source of bugs is assuming that the built-in VBA function returns a special Cancel value. It does not: InputBox returns a string, and pressing Cancel returns a zero-length string (""). Submitting the dialog with an empty field also returns "". Therefore, code that checks only Len(response) = 0 can detect that no text came back, but cannot tell whether the user canceled or deliberately submitted a blank answer.

This limitation matters when the next action differs. If both outcomes mean “do nothing,” checking for an empty string is adequate. If the program must distinguish Cancel from an accepted blank, use a different interaction, such as a custom UserForm with separate controls or Excel’s Application.InputBox method and a suitable check for its Cancel result.

Do not treat the prefilled default as proof that the user accepted it. A canceled dialog does not return the displayed default. If you use the built-in function, an empty return should not trigger a change to the workbook unless your code intentionally interprets that result as a valid instruction.

InputBox function and Application.InputBox compared

In Excel VBA, InputBox and Application.InputBox are related but different choices. The built-in function is convenient for straightforward text. Excel’s method adds a Type argument that can request a number, logical value, range, or other supported input type. It also has a different Cancel result: the method returns Boolean False when the user cancels.

The method’s Default argument also supplies the initial value shown in the field. Here is a numeric example. Save a copy of the workbook before running a macro; this example only displays a message, but macros that follow it with edits cannot be reversed using Ctrl+Z.

Sub AskForQuantity()
    ' Request a number and distinguish Cancel from a numeric response.
    Dim answer As Variant

    answer = Application.InputBox( _
        Prompt:="Enter a quantity:", _
        Title:="Quantity", _
        Default:=1, _
        Type:=1)

    If VarType(answer) = vbBoolean Then
        MsgBox "The dialog was canceled."
    Else
        MsgBox "Quantity entered: " & CStr(answer)
    End If
End Sub

Here, Type:=1 requests a number, and Default:=1 displays 1 as the initial suggestion. The result is declared as a Variant because it may hold the requested value or the Boolean value returned on Cancel. Checking the variant’s type avoids confusing Cancel’s Boolean False with a legitimate numeric zero.

When Application.InputBox is called with Type:=8, the user selects a range. The return value is a range object, so VBA code normally assigns it with Set; it should not be handled as if it were an ordinary text response. Use the method only when its type checking or Cancel behavior is useful, since its extra options make it more involved than the basic function.

Validate the response before using it

Neither kind of input dialog replaces application-level checks. A numeric type request can help restrict what the Excel method accepts, but your macro should still check that the value fits the task. A text prompt can accept unexpected words, spaces, or punctuation. Decide what counts as valid before writing input to a worksheet, using it in a calculation, or passing it to another procedure.

For a text value, Trim$ can remove leading and trailing spaces before you test whether the result is empty. Be careful not to trim when spaces are meaningful, such as in a deliberately formatted identifier. For a number entered through the basic function, IsNumeric can help identify numeric-looking text, but you still need to convert it and check its allowed range. For a list of permitted choices, compare the response with that list or offer a control that makes invalid choices impossible.

Keep the user informed when validation fails. A useful prompt identifies the expected format, and a useful error message says what to enter next. Avoid silently substituting the default after an invalid response unless that behavior is explicit; otherwise the workbook may appear to accept an answer it actually discarded.

Common mistakes with the Default argument

  • Putting the value in the title position. The second argument is the title. Supply a title before the default when both are needed.
  • Expecting the default to be compulsory. It is editable and can be deleted. Validate the final response.
  • Assuming Cancel returns the default. The built-in function returns an empty string on Cancel, not the displayed starting value.
  • Assuming an empty result always means Cancel. With the built-in function, Cancel and submitting a blank field both produce an empty string.
  • Using a text box for a constrained choice. A default does not limit the user to approved options. Validate it or choose a more suitable interface.
  • Confusing the VBA function with an Excel formula. InputBox is called by VBA code; it is not a worksheet function to enter in a cell.

The same basic VBA language is available in Excel for Microsoft 365 on Windows and Mac, though some Excel features and automation interfaces differ between platforms. These examples use the standard VBA dialog and do not depend on Windows-only APIs. If a macro later uses operating-system calls or other platform-specific components, check those separately before relying on it on a Mac.

Frequently Asked Questions

What is the default value in a VBA InputBox?
The default is the optional third argument. It is the text initially displayed in the input field, for example InputBox("Enter a name:", "Name", "Alex"). If that argument is omitted, the field starts empty.

How do I set an InputBox default from a cell?
Read the cell into a variable, make sure it contains a usable value, and pass that variable as the third argument. For example, a variable named suggestion can be used in InputBox("Enter a name:", "Name", suggestion). Convert or format it first if the cell contains a date or number that should appear in a particular text format.

Can the user change or delete the default?
Yes. The default is prefilled text, not a locked value. The user can edit it, replace it, or clear it and submit an empty response.

Does InputBox return the default when the user presses Cancel?
No. The built-in VBA function returns an empty string on Cancel. It also returns an empty string when the user submits an empty field, so the function alone cannot distinguish those two actions.

How can I tell if an Excel Application.InputBox was canceled?
Application.InputBox returns Boolean False on Cancel. Store the result in a Variant and check its type when the requested input could itself be a value such as zero that might otherwise be confused with False.

Can I use InputBox as a worksheet formula?
No. It is a VBA function called from a macro or other VBA procedure, not a formula entered in a worksheet cell. If you need guided input directly in a worksheet, use cells with validation or build a suitable form instead.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.