VBA MsgBox Line Breaks: Constants, Examples, and Fixes

VBA & macros · Updated November 18, 2026

To add a line break to a VBA MsgBox message, join the text with vbCrLf, as in MsgBox "First line" & vbCrLf & "Second line". The message box displays the two text parts on separate lines; for a platform-appropriate newline, you can also use vbNewLine.

A basic VBA MsgBox line break

In VBA, the ampersand joins text together, and vbCrLf inserts a carriage return followed by a line feed. Put it between the pieces of text wherever the message should wrap onto a new line. For example, this macro shows a two-line message with an information icon:

Sub ShowTwoLines()
    Dim messageText As String

    ' Join two text lines with a Windows-style line break.
    messageText = "The file was saved." & vbCrLf & "You can close this window."
    MsgBox messageText, vbInformation, "Save complete"
End Sub

The first argument to MsgBox is the message text. The optional second argument controls the buttons and icon, and the optional third argument supplies the title shown in the dialog’s title bar. In the example, vbInformation requests an information icon. The line break belongs in the first argument, not in the title.

Before running a macro that changes a workbook, save a copy of the file. VBA macros cannot be undone with Ctrl+Z, even if their effects seem small. To run the example in Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11, choose Insert > Module, paste the procedure into the module, and run it with F5 while the cursor is inside the procedure. On a Mac, the Visual Basic Editor is available from Tools > Macro > Visual Basic Editor; keyboard shortcuts can vary with the keyboard and macOS settings.

What vbCrLf and vbNewLine mean

vbCrLf is a built-in VBA constant made from two control characters: carriage return (CR) and line feed (LF). It is the familiar Windows newline sequence, and it is a straightforward choice for a normal Excel VBA message box on Windows. You do not need to type the control characters yourself or install anything to use it.

vbNewLine is another built-in constant that represents a newline appropriate to the environment. It is useful when code may run on more than one operating system and you want VBA to choose the platform’s newline convention. Excel’s MsgBox can display a line break made with either constant. For ordinary Windows-only Excel macros, vbCrLf is common and clear; for cross-platform intent, vbNewLine communicates that choice.

VBA also provides vbCr and vbLf individually. You may see examples using Chr(13) & Chr(10), which produces the same CR-plus-LF sequence as vbCrLf. The named constant is generally easier to read and less error-prone than numeric character codes. These are separators in a string, not special MsgBox options.

Choosing the right separator

For most messages in Windows Excel, use vbCrLf. It makes the intended break explicit and matches the standard Windows text newline. Use vbNewLine if the same VBA code is expected to run in environments with different newline conventions. Either is preferable to manually inserting a line feed and hoping the receiving control interprets it as intended.

  • Use vbCrLf for a conventional Windows Excel MsgBox and for code where the Windows newline is desired.
  • Use vbNewLine when portability across platforms is a deliberate requirement.
  • Use Chr(13) & Chr(10) only when you have a specific reason to express the character codes directly; it is not necessary for a regular message.
  • Avoid relying on vbLf alone for a standard Windows message unless you have verified that the particular control or output destination handles it as expected.

These constants do not change the dialog’s size on demand or guarantee that every line will fit. MsgBox uses a standard dialog layout, so long lines may wrap according to the available width. If the message is long, concise wording and intentional line breaks are more reliable than trying to force a particular pixel width.

Building messages with several lines

Concatenate a separator each time the message should move to another line. You can also use repeated separators to leave a blank line between sections. The following example puts a blank line between the status and the next step:

Sub ShowStatus()
    Dim messageText As String

    ' Two consecutive breaks create an empty line.
    messageText = "Import finished." & vbCrLf & vbCrLf & _
                  "Review the totals before saving."
    MsgBox messageText, vbInformation, "Import status"
End Sub

The space and underscore at the end of the first assignment line are VBA’s line-continuation syntax: they let a long statement continue on the next physical code line. They do not add a break to the displayed message. Only the vbCrLf values inside the string expression affect what the user sees.

You can place a separator at the beginning or end of the message, but doing so creates an empty first or last line, which usually looks unintended. For predictable formatting, put separators only between meaningful sections and check the final message for accidental consecutive breaks.

Combining line breaks with variable values

A MsgBox can combine fixed labels, variable values, and line breaks. Use the ampersand between each component, and make sure variables are converted to readable text when necessary. VBA will often convert numbers when concatenating them with strings, but formatting a value explicitly can make the result clearer, especially for dates and currency.

Sub ShowOrderDetails()
    Dim customerName As String
    Dim orderNumber As Long
    Dim messageText As String

    ' Example values; replace these with workbook data as needed.
    customerName = "Avery"
    orderNumber = 4821

    messageText = "Customer: " & customerName & vbCrLf & _
                  "Order number: " & CStr(orderNumber)
    MsgBox messageText, vbInformation, "Order details"
End Sub

Here CStr converts the number to a string, and the newline separates the two labeled values. If a value comes from a worksheet cell, read it into a variable or include it in the expression, taking care to handle blank cells and errors appropriately. A line break changes presentation only: it does not validate the values, alter the worksheet, or make a message interactive.

Common line-break problems and fixes

If a message appears on one line, first check that the separator is inside the expression assigned to the message text and joined with ampersands. A frequent mistake is putting vbCrLf inside quotation marks. In that case VBA treats it as the literal letters rather than the newline constant. Compare the correct form, "First" & vbCrLf & "Second", with the incorrect literal text, "First vbCrLf Second".

  • Missing ampersand: Each separate string or variable must be joined with &. A missing operator can produce a compile error rather than a formatted message.
  • Wrong quotation marks: In VBA code, string values need straight double quotes. Curly “smart quotes” copied from formatted text can trigger a syntax error.
  • Using a worksheet formula escape: CHAR(10) is familiar from worksheet formulas, but it is not the usual VBA constant to use in a MsgBox. Prefer vbCrLf or vbNewLine.
  • Expecting a line break in the title: The title is a separate argument from the message. Keep line breaks in the message argument; a title is intended to be a short caption.
  • Too much text: A MsgBox is best for a brief notification or question. Long content may be difficult to read in a fixed dialog; use a worksheet, UserForm, or another display method for substantial text.
  • Confusing code lines with message lines: Pressing Enter in the VBA editor starts a new code line; it does not insert a line break into a string. Add the newline constant to the string expression instead.

If VBA highlights the statement when you run the macro, check that every opening quote has a closing quote and that a line-continuation underscore is preceded by a space and is the last non-space character on that code line. If the macro compiles but the message is cramped, shorten the text or split it into a few readable lines rather than adding many empty lines.

Line breaks do not control buttons or dialog layout

It is easy to mix up the message text with the other arguments to MsgBox. The general form is MsgBox(prompt, buttons, title): the prompt is the displayed text, buttons selects the available buttons and optional icon, and title sets the caption. A newline in the prompt does not add buttons, change which response is returned, or make the dialog wider.

For example, a Yes/No question can have a two-line prompt by using vbYesNo as the buttons argument and putting vbCrLf in the prompt. The return value still indicates the button selected, such as vbYes or vbNo. If the result matters, capture it in a variable declared as a suitable type and branch on that result; formatting the question and handling the answer are separate tasks.

When another display method is better

MsgBox is useful when a macro needs to show a short status, warning, or confirmation and pause for the user. It is modal: the user must respond to the dialog before continuing to interact with the workbook. A few well-separated lines can make such a message easier to scan, but a dialog is not a good substitute for a report or a long set of instructions.

For information that users need to inspect, copy, filter, or revisit, consider writing it to cells on a worksheet. For a custom interface with fields, controls, or carefully arranged content, a VBA UserForm offers more layout control than MsgBox. For developer diagnostics that should not interrupt a macro, Debug.Print sends text to the Immediate window in the Visual Basic Editor; it is not shown as a pop-up to workbook users. Choose based on whether the content is a brief interruption, persistent data, a custom interface, or diagnostic output.

Frequently Asked Questions

What is the simplest way to start a new line in VBA MsgBox?

Join the text with vbCrLf: "First line" & vbCrLf & "Second line". This is the standard, readable approach for a Windows Excel VBA message.

Can I use vbNewLine instead of vbCrLf?

Yes. vbNewLine supplies a newline appropriate to the current environment, while vbCrLf explicitly represents carriage return plus line feed. Both can separate lines in a MsgBox prompt.

How do I add a blank line between paragraphs?

Use two consecutive newline constants between the text parts, for example "First paragraph" & vbCrLf & vbCrLf & "Second paragraph". One separator starts the next line; the second leaves an empty line.

Why does my MsgBox show the text vbCrLf?

It is probably inside quotation marks, so VBA reads it as ordinary text. Remove the quotes around the constant and concatenate it between quoted text sections with ampersands.

Does pressing Enter in the VBA editor create a line break in the message?

No. Enter creates a new line in the source code. To add a displayed line break, include vbCrLf or vbNewLine in the message string.

Can a MsgBox line break make the dialog wider?

No. A line break changes where the prompt text starts a new line; it does not set the dialog’s width. If the message is too wide or too long to read comfortably, shorten it or use a worksheet or UserForm 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.