VBA InputBox New Line: Add Line Breaks to Prompts

VBA & macros · Updated November 3, 2026

VBA InputBox New Line: Add Line Breaks to Prompts

To put a new line in a VBA InputBox prompt, join the prompt text with vbCrLf or vbNewLine. For example, "First line" & vbCrLf & "Second line" displays the second part beneath the first; it does not make the InputBox’s answer field accept multiple lines.

How a new line works in an InputBox prompt

VBA builds a prompt as a string, and the line-break constant becomes part of that string. When the dialog displays the prompt, it interprets the break as a new line. This is useful when one sentence is not enough to explain what to enter, or when you want to separate an instruction from an example.

In Excel for Microsoft 365 on Windows, vbCrLf is a common explicit choice. It represents a carriage return followed by a line feed. The VBA constant vbNewLine is another clear option when you want a platform newline. Both are preferable to typing a line break into the middle of a quoted string, which can make VBA code harder to read and may cause a syntax error.

The ampersand (&) joins the text on either side of the break. You can use the same pattern more than once to create several prompt lines:

Sub AskForDetails()
    Dim answer As String

    ' Save a copy of the workbook first; macros cannot be undone with Ctrl+Z.
    answer = InputBox( _
        "Enter the department name." & vbCrLf & _
        "Example: Customer Support", _
        "Department")
End Sub

The dialog’s prompt will show the instruction and example on separate lines. The second argument supplies the dialog title. The underscore at the end of a code line is VBA’s line-continuation character; it keeps a long statement readable and is not itself a line break in the displayed prompt.

Choosing between vbCrLf, vbNewLine, and Chr

For most Windows Excel macros, vbCrLf is a dependable, readable way to create a visible line break. vbNewLine is a convenient named constant for a newline, especially if code may be used in more than one environment. In ordinary Excel VBA prompts, either is usually suitable.

You can also write a line break using character codes. Chr(13) & Chr(10) makes the carriage-return/line-feed pair explicit, while Chr(10) represents a line feed. These forms can be helpful when adapting code that already works with character codes, but they are less self-explanatory to many readers than the named constants.

  • vbCrLf: a clear, explicit choice commonly used in Windows VBA.
  • vbNewLine: a named newline constant that makes the purpose easy to recognize.
  • Chr(13) & Chr(10): an explicit character-code equivalent of a CR-LF break.
  • Chr(10): a line-feed character that can work, though a CR-LF pair is often the safer conventional choice for Windows dialogs.

Use one approach consistently within a prompt unless you have a specific compatibility reason to mix them. Mixing different break characters can make the code less clear without improving the dialog for its user.

Writing a readable prompt with multiple lines

A line break helps most when each line has a distinct job. Put the main request first, then add a short constraint, example, or explanation. Avoid turning the prompt into a block of documentation: an InputBox is a small dialog, and long text can be difficult to scan or may not fit comfortably in the available space.

For example, a prompt asking for a worksheet name could give both the action and a useful example:

Sub GetSheetLabel()
    Dim sheetLabel As String

    ' Save a copy of the workbook first; macros cannot be undone with Ctrl+Z.
    sheetLabel = InputBox( _
        "Type the label for the new worksheet." & vbCrLf & _
        "Example: April Summary", _
        "Worksheet label")
End Sub

When designing the wording, consider these practical points:

  • Keep the first line direct so the user immediately knows what is being requested.
  • Use a separate line for an example or formatting rule rather than crowding the instruction.
  • Choose a meaningful title, such as Worksheet label, instead of repeating a generic title like Input.
  • Do not rely on blank lines to create a specific visual gap; dialog sizing and rendering can affect how much space appears.
  • Keep the prompt concise and test it with the actual text and dialog title used in the workbook.

InputBox function versus Application.InputBox

Excel VBA has both the built-in InputBox function and Excel’s Application.InputBox method. Both can receive a prompt string containing vbCrLf, so the basic line-break technique is the same. The important difference is what the dialog can accept and how the result is returned.

The built-in InputBox returns text. Application.InputBox can use its Type argument to request other kinds of input, such as a number, a range, or text. For a text response, set Type:=2. Its result should generally be stored in a Variant, because cancelling an Application.InputBox returns the Boolean value False, which is different from an empty text response.

Sub AskWithApplicationInputBox()
    Dim response As Variant

    ' Save a copy of the workbook first; macros cannot be undone with Ctrl+Z.
    response = Application.InputBox( _
        Prompt:="Enter a project name." & vbCrLf & _
                "Use a short, recognizable label.", _
        Title:="Project name", _
        Type:=2)

    If VarType(response) = vbBoolean Then Exit Sub
End Sub

That final check detects the Boolean cancel result before the macro treats it as a text entry. Choose the built-in function for a straightforward text prompt. Choose Application.InputBox when its input-type options are useful. Neither choice turns the answer area into a multiline text editor.

Why typing \n does not create a new line

VBA does not use the backslash-n convention found in some other programming languages. If you write "First line\nSecond line", the backslash and letter n are ordinary characters in the string; they are not interpreted as a line break. Use vbCrLf, vbNewLine, or an appropriate Chr expression instead.

Another common mistake is placing a physical line break between the opening and closing quotation marks in a VBA string literal and expecting the editor to treat it as prompt formatting. Keep each quoted text segment on a valid code line, then join the segments with & and the newline constant. If the VBA statement itself needs to span several editor lines, use the line-continuation character after a space.

Common problems and how to fix them

If the prompt still appears on one line, first check that the newline constant is actually included in the string being passed to InputBox. It must be joined with &; writing vbCrLf in a comment or in a different variable will not affect the prompt. Also make sure the code you are running is the updated procedure, not another macro with a similar name.

  • The break appears as text: Check for a literal \n or a misspelled constant. Use vbCrLf or vbNewLine.
  • VBA reports a syntax error: Check the quotation marks, ampersands, commas, and line-continuation underscores. Each text segment needs a matching pair of quotes.
  • The prompt is hard to read: Shorten the wording and put the instruction before the example. A break separates lines, but it does not enlarge the dialog indefinitely.
  • The answer is blank after Cancel: With the built-in function, Cancel and submitting an empty response both produce an empty string. If distinguishing those actions matters, use a design that can report cancellation separately, such as a suitable form.
  • The answer needs several lines: The standard InputBox answer field is a single-line entry field. Changing the prompt’s line breaks does not change that control.

For code that will be shared between Windows and Mac versions of Excel, check the appearance on the target platform as well as the code. VBA constants are available in VBA, but dialog layout can differ by platform. Excel for the web does not run VBA macros, so an InputBox macro is for desktop Excel rather than the browser version.

Can a user enter multiple lines in the answer?

No. A line break in the prompt affects only the explanatory text above the input field. The standard VBA InputBox and Application.InputBox provide a single-line answer field; they are not multiline editors. Pasting text containing line breaks is not a reliable way to turn that field into a multiline control.

If users need to type or edit paragraphs, build a UserForm with a TextBox control and set that control’s MultiLine property to True. A UserForm gives you more control over labels, buttons, and validation, but it takes more setup than a one-line prompt. For a short value such as a name, code, or date, an InputBox is usually simpler.

When to use a UserForm or another alternative

A standard InputBox is a good fit when the macro needs one short response and a brief explanation. If the interaction needs several fields, a multiline comment, validation messages, or clearly distinct OK and Cancel behavior, a UserForm is generally more suitable. It can present a larger text area and let you control how the form closes and what values the macro receives.

For a limited set of choices, consider a worksheet selection or a form control rather than asking the user to type a value that must match a specific option. This can reduce spelling errors. If you keep the InputBox, validate the returned text before using it—for example, check that it is not empty and that it matches an allowed worksheet or category. A line break improves instructions; it does not validate the answer.

Before running any macro that changes workbook data, save a separate copy of the workbook. VBA actions cannot generally be reversed with Excel’s Ctrl+Z undo command. This is especially important when adding validation or follow-on operations to an InputBox procedure, since the dialog itself may be only the first step in a larger macro.

Frequently Asked Questions

What code puts a new line in a VBA InputBox?
Join the prompt text with vbCrLf, such as "First line" & vbCrLf & "Second line". vbNewLine is another suitable option.

Can I use vbNewLine in Excel VBA?
Yes. Use it between two string sections with the ampersand operator. In Windows Excel VBA, vbCrLf is also a commonly used explicit line break.

Why does \n show up in my InputBox?
VBA does not interpret backslash-n as a newline escape. It treats those characters literally. Replace it with vbCrLf or vbNewLine.

Can InputBox accept a multiline answer?
No. Its answer field is for a single line of text. Use a UserForm with a multiline TextBox if users need to enter paragraphs or line-separated notes.

Does the same line-break code work with Application.InputBox?
Yes. Add the newline to the Prompt string in the same way. Remember that Application.InputBox can return Boolean False when cancelled, so handle its result appropriately.

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.