VBA MsgBox New Line: Add Line Breaks to Messages

VBA & macros · Updated November 3, 2026

VBA MsgBox New Line: Add Line Breaks to Messages

To add a new line in a VBA MsgBox, join the message text with vbCrLf or vbNewLine where you want the break. For example, use "First line" & vbCrLf & "Second line". The message box will display the two text parts on separate lines. You can use this in Excel for Microsoft 365 on Windows, and the same VBA constants are available in desktop Excel for Mac.

What You’ll Need

  • A desktop version of Excel with VBA support. Excel for the web can open a macro-enabled workbook, but it cannot run or edit VBA macros.
  • A workbook in which you can run a macro. If you are editing an existing workbook, save a separate copy before running code. Macro actions cannot be undone with Ctrl+Z.
  • Access to the Visual Basic Editor. In Windows Excel, press Alt+F11. On a Mac, use Option+F11 (you may also need to hold Fn, depending on your keyboard), or open the Visual Basic Editor from Excel’s Tools menu.

Step-by-Step

  1. Open the Visual Basic Editor. In Excel for Windows, press Alt+F11. If the shortcut is assigned to a laptop function key, try Fn+Alt+F11. On Mac, use Option+F11 or the Tools menu. The editor is where you write and run VBA; the line break is added to the message text in your code, not by changing an Excel cell setting.
  2. Insert a standard module. In the editor, select your workbook in the Project Explorer. If that panel is hidden, press Ctrl+R on Windows or use View > Project Explorer. Choose Insert > Module. A blank code window appears. A standard module is a convenient place for a small macro that you want to run manually.
  3. Build the message with a line-break constant. Type the parts of the message as text in quotation marks, and join them with the ampersand operator, &. Put vbCrLf between the parts that should appear on separate lines. This complete example shows a three-line message:
Sub ShowLineBreaks()
    Dim customerName As String
    Dim messageText As String

    customerName = "Jordan"

    ' & joins text; vbCrLf starts a new line.
    messageText = "Hello, " & customerName & "." & vbCrLf & _
                  "Your report is ready." & vbCrLf & _
                  "Please review the totals."

    MsgBox messageText, vbInformation, "Report status"
End Sub

The first line includes the value of customerName. Each vbCrLf inserts a break after the preceding sentence, so the message appears as three lines. The underscore at the end of the first two assignment lines is VBA’s line-continuation character; it lets you split a long statement across source-code lines. It is not what creates the breaks in the message.

  1. Choose the break constant that suits your code. vbCrLf is a clear, commonly used choice for Windows VBA. vbNewLine is another readable option and represents the platform’s newline sequence. Replace each vbCrLf in the sample with vbNewLine if you prefer it. Both constants are different from typing the characters \n, which VBA does not interpret as a newline escape.
  2. Run the macro. Save your workbook as a macro-enabled workbook (.xlsm) if you need to keep the macro. In the editor, click inside ShowLineBreaks and press F5, or return to Excel and run it from Developer > Macros. If the Developer tab is not visible on Windows, enable it through File > Options > Customize Ribbon and select Developer. Excel for Mac has its own ribbon customization options; the tab’s visibility does not change how the VBA line break works.
  3. Check the message and adjust the break positions. The message box should show “Hello, Jordan.”, “Your report is ready.”, and “Please review the totals.” on separate lines. Move a break by moving the vbCrLf or vbNewLine in the expression. Add another constant for each additional new line. If you want a blank line between two sections, insert two break constants in a row.

For instance, the expression "Summary" & vbCrLf & vbCrLf & "Complete" displays an empty line between “Summary” and “Complete.” Each break starts a new line; two consecutive breaks leave one line with no text. This can make a short message easier to scan, but too many blank lines may make the dialog unnecessarily tall.

Common Mistakes

  • Using \n as if VBA used C-style escapes. VBA does not convert a backslash followed by n into a line break. It will typically show those characters as part of the message. Use vbCrLf or vbNewLine instead.
  • Forgetting to join the text. A break constant needs to be joined to the surrounding text with &. For example, put an ampersand before and after the constant when it sits between two quoted strings. Without the correct joins, VBA may report a syntax error or the expression may not form the message you intended.
  • Leaving out quotation marks around message text. Ordinary words in a message need double quotes. A variable such as customerName should not be quoted if you want VBA to insert its value; quoting it would display the variable name literally.
  • Confusing a code continuation with a displayed line break. The underscore used at the end of a VBA source line only continues the statement in the editor. The constant inside the string expression is what adds a new line to the dialog. You can write the whole expression on one source line and still create multiple displayed lines.
  • Putting the break outside the message expression. The constant must be part of the text passed to MsgBox, either directly or through a string variable. Adding it on an unrelated line does not change what the dialog displays.

Tips

  • Use a variable for a message that is growing. Building the text in a named variable makes it easier to review punctuation, spacing, and line breaks before calling MsgBox. It also makes the final MsgBox statement easier to read.
  • Put breaks at natural reading points. Separate a greeting, status, and instruction rather than splitting a sentence arbitrarily. A MsgBox is a small dialog, so concise lines are usually easier to read than one long paragraph.
  • Keep spaces around words intentional. A line break does not add spaces before or after the text. If two text pieces should remain on the same line, include the needed space inside a quoted string; for a new line, put the break exactly between the two parts.
  • Use a title and an icon when they clarify the message. In MsgBox messageText, vbInformation, "Report status", the second argument selects an information icon and the third supplies the dialog title. These arguments are optional and do not control line breaks.
  • Test with realistic text. A name, file path, or status that is longer than your sample can wrap within the dialog. Line breaks establish line boundaries, but they do not set a fixed width or guarantee that every line fits on one visual row.
  • Keep the macro simple and reversible. This example only displays a dialog, but macros can also edit workbook content. Save a copy before running unfamiliar code, and remember that Ctrl+Z does not undo VBA actions.

Troubleshooting

The dialog displays “\n” instead of moving to a new line: Replace the backslash-n characters with vbCrLf or vbNewLine. VBA string literals do not use \n as a newline escape.

VBA highlights the assignment or reports a compile error: Check the quotation marks, ampersands, and any underscores used for source-code continuation. A line-continuation underscore must be the last non-space character on its code line, and it must be preceded by a space. Also confirm that each quoted string is closed before the next operator or constant.

The macro does not run: Confirm that you are using desktop Excel rather than Excel for the web, that the workbook is saved in a macro-capable format, and that macros are permitted by your organization’s security settings. In the editor, place the cursor inside the intended procedure before pressing F5. Do not lower security settings broadly just to run an unfamiliar macro.

The message is still one long line: Verify that the code actually passes the variable or expression containing the break to MsgBox. For example, if you build messageText correctly but call MsgBox "A different message", the dialog will not use the built string. Check that the break constant has not been accidentally placed inside quotation marks.

The dialog looks cramped or text wraps unexpectedly: Shorten the lines, remove unnecessary blank lines, or split the message into more concise phrases. A MsgBox controls its own dimensions; inserting a break cannot force a particular width. For long help text or content requiring custom layout, a UserForm may be more suitable than a standard message box.

Frequently Asked Questions

Should I use vbCrLf or vbNewLine?

Both are valid VBA choices for inserting a newline in a MsgBox. vbCrLf explicitly names the carriage-return and line-feed pair and is widely used in Windows VBA examples. vbNewLine expresses the platform’s newline sequence. Choose one and use it consistently; for ordinary Excel VBA messages, either is suitable.

Can I add more than one new line?

Yes. Add a break constant at each point where the message should continue on a new line. Use two constants together to leave a blank line between sections. Keep the result readable and avoid adding empty lines that do not help explain the message.

Can I start the message with a blank line?

Yes. Put a newline constant at the beginning of the message expression, before the first text segment. For example, a leading vbCrLf creates an empty first line. Usually, it is clearer to begin with the first useful word unless the blank space is intentional.

Does the line-break method work in Excel for Mac?

VBA string constants such as vbCrLf and vbNewLine are available in desktop Excel for Mac as well as Windows. The way you open the Visual Basic Editor or customize the ribbon can differ. Excel for the web does not run VBA macros.

Can I use a line break in the MsgBox title?

The title argument is intended to be a short dialog caption, not a multi-line message area. Put the detailed, multi-line text in the prompt argument—the first argument to MsgBox—and keep the title concise. This makes the message clearer and more predictable.

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.