VBA InputBox Default Value: Set and Use It

VBA & macros · Updated November 18, 2026

In VBA, set an InputBox’s default value with its third argument: InputBox(prompt, title, default). For example, InputBox("Enter a quantity:", "Order", "1") opens with 1 already in the editable text field.

Where the default value goes

The VBA InputBox function takes a required prompt followed by optional arguments. Its third argument is Default, so the order is important: the title comes second, and the default comes third. You can omit the title and other optional arguments, but you cannot skip an earlier argument and provide a later one by position.

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

For instance, this call uses all three of the common arguments:

Dim answer As String

' Show a prompt, a title, and prefilled text.
answer = InputBox("Enter a department name:", "Department", "Sales")

The dialog appears with “Enter a department name:” as its prompt, “Department” as its title, and “Sales” in the entry field. The user can keep that text, edit it, or replace it before clicking OK. The default is an initial value, not a locked value or a hint that disappears when the user starts typing.

Use a default without a title

Because the title argument is before the default argument, a positional call cannot supply a default as the second argument. For example, InputBox("Enter a name:", "Alex") sets the dialog title to “Alex”; it does not prefill the entry field with that text. To use a default and keep the title blank, provide an empty string for the title:

Dim userName As String

' The empty second argument leaves the title unspecified.
userName = InputBox("Enter a name:", , "Alex")

In VBA, the omitted argument between the commas is allowed because the title is optional. Another clear option is to name the arguments explicitly:

Dim userName As String

' Named arguments make the purpose of each value clear.
userName = InputBox(Prompt:="Enter a name:", Default:="Alex")

Named arguments can make a call easier to read, especially when using optional parameters. They also reduce the chance of accidentally putting a value in the wrong position. If the code needs a custom title, include it explicitly, such as InputBox(Prompt:="Enter a name:", Title:="Contact", Default:="Alex").

What the function returns

The VBA InputBox function returns the text entered by the user as a string. If the user accepts the suggested value without changing it, the returned string is that value. If the user edits the entry, the edited text is returned instead. The function does not automatically convert text such as 25 into a number or check whether the entry is valid for your task.

That means a default can guide the user, but it does not enforce a rule. If a macro needs a whole number, for example, it should check the returned text before using it in a calculation. A default of 1 does not stop someone from typing many, leaving the box empty, or entering a decimal.

Also note that the function returns an empty string if the user clicks Cancel. It returns an empty string if the user clicks OK after clearing the field, too. Those two actions are therefore indistinguishable from the function’s return value alone. If your workflow must tell Cancel apart from an empty response, consider Excel’s Application.InputBox method, which has different behavior.

Example: offer a useful starting value

A practical default is a value that is likely to be useful but remains easy to change. The following example asks for a worksheet name and starts with a suggested name. It exits if the returned text is blank, whether that happened through Cancel or by submitting an empty field.

Sub AskForWorksheetName()
    Dim sheetName As String

    ' Prefill a suggested worksheet name.
    sheetName = InputBox( _
        Prompt:="Which worksheet should the macro use?", _
        Title:="Choose a worksheet", _
        Default:="Summary")

    ' InputBox returns an empty string for Cancel or an empty response.
    If Len(sheetName) = 0 Then Exit Sub

    MsgBox "You entered: " & sheetName
End Sub

Before running a macro, save a copy of the workbook: VBA changes cannot be undone with Ctrl+Z. This example only displays the response, but a real macro might use it to find a worksheet. In that case, it should also check that a sheet with the entered name exists before trying to use it.

If surrounding spaces should not count as part of the answer, normalize the text with Trim$ before checking it. For example, a response containing only spaces otherwise has a length greater than zero. Decide how to handle letter case and spelling based on the task; the InputBox function does not make those decisions for you.

Choose defaults that are clear and safe

A good default reduces typing without misleading the person using the macro. Use a value that makes sense in the context of the prompt, and make the prompt explain what is expected. A field prefilled with 2026, for example, is more helpful if the prompt asks for a year rather than simply saying “Enter a value.”

  • Use a likely answer: A common folder name, report period, or starting quantity may be a sensible suggestion.
  • Keep the value editable: The standard VBA InputBox does not restrict what the user can type.
  • Avoid risky assumptions: Do not prefill a destructive choice or an important setting and then treat acceptance as proof that the user reviewed it.
  • Make units and formats apparent: If the expected entry is a date, percentage, or identifier, say so in the prompt or show an example.
  • Validate after entry: Check that the response is present and usable before relying on it in later code.

A default is not a substitute for confirmation when an action has significant consequences. For example, prepopulating a path to a file that will be overwritten may make a macro faster, but the code should still handle errors and use an appropriate confirmation step before replacing data.

InputBox function versus Application.InputBox

Excel VBA offers two similarly named options that serve different needs. The built-in InputBox function is simple and returns text. Excel’s Application.InputBox method adds a Type argument so the dialog can request a particular kind of input, including a number, a formula, or a cell reference. It is often the better choice when input needs to be constrained or when a user should select a range.

For example, this method asks for a number and supplies a starting value:

Sub AskForNumber()
    Dim response As Variant

    ' Type 1 requests a numeric value; Cancel returns Boolean False.
    response = Application.InputBox( _
        Prompt:="Enter a number:", _
        Title:="Number", _
        Default:=1, _
        Type:=1)

    ' Check the Variant before treating it as a number.
    If VarType(response) = vbBoolean Then
        If response = False Then Exit Sub
    End If

    MsgBox "You entered: " & CStr(response)
End Sub

With Application.InputBox, Cancel returns the Boolean value False. The declared Variant lets the variable hold that Boolean as well as the accepted input. Do not store the result immediately in a numeric variable if you need to detect Cancel first: a conversion can make cancellation harder to distinguish from a valid value. The Type setting controls what Excel accepts, but code should still be written with the intended return type and cancellation behavior in mind.

For a basic text question, the ordinary InputBox function is often the shorter and clearer choice. For a number or range selection in Excel, Application.InputBox can provide more appropriate input behavior. Neither option creates a full custom form; for multiple fields, detailed instructions, or more control over validation and layout, a UserForm may be a better fit.

Common mistakes and troubleshooting

The most frequent mistake is placing the default in the title position. Remember the sequence: prompt, title, default. Another common issue is assuming the suggested text is a validation rule. Users can replace it, so code that depends on a specific format must check the response.

  • The wrong text appears in the title bar: The proposed default was probably passed as the second positional argument. Put a title before it, or use named arguments.
  • The default is missing: Check that it is the third argument, that the string is not empty, and that the call is actually reaching the expected InputBox.
  • Cancel behaves like blank input: This is expected for the VBA InputBox function. Both Cancel and OK with an empty field return a zero-length string.
  • A numeric answer causes a type problem: The regular function returns text. Convert and validate it deliberately, or consider Application.InputBox with a numeric Type.
  • The dialog does not run in a browser: Excel for the web does not run VBA macros. Use desktop Excel to run VBA; Excel for Windows and Mac have desktop VBA support, though platform-specific code and interface details can differ.

If you use the optional position arguments, remember that they control where the dialog appears, not the default text. The function’s argument order remains the same. For most macros, leaving position arguments out lets the application place the dialog without adding unnecessary complexity.

Frequently Asked Questions

What is the default argument in VBA InputBox?
The third argument is Default, after the prompt and optional title. For example, InputBox("Enter a code:", "Code", "A12") starts with A12 in the entry field.

Can I set a default without setting a title?
Yes. Omit the optional title while supplying the third argument, as in InputBox("Enter a name:", , "Alex"). You can also use named arguments, such as InputBox(Prompt:="Enter a name:", Default:="Alex").

Can the user change the InputBox default?
Yes. The default is prefilled text, not a restriction. The user can accept it, edit it, or replace it. Validate the returned string if the macro requires a particular format or value.

Does Cancel return the default value?
No. With the VBA InputBox function, Cancel returns an empty string, as does clicking OK after clearing the field. Excel’s Application.InputBox method instead returns Boolean False when canceled.

How do I make the default a number?
The regular InputBox function still returns text, even if its default looks numeric. Convert and validate that text in your code, or use Application.InputBox with Type:=1 when a numeric response is appropriate.

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.