VBA MsgBox Line Breaks: Add a New Line to a Message

VBA & macros · Updated November 18, 2026

To start a new line in a VBA MsgBox, join the text with vbCrLf: use MsgBox "First line" & vbCrLf & "Second line". The message box displays the second string below the first; add another vbCrLf if you want a blank line between sections.

Basic syntax for a MsgBox line break

A MsgBox prompt is a string. In VBA, the ampersand operator, &, joins strings together, while vbCrLf supplies a carriage return followed by a line feed. Together, they make a line break in the displayed message. The line break belongs inside the prompt string; it does not create a new line in the VBA editor itself.

For example, the expression "First line" & vbCrLf & "Second line" combines three pieces: the first line of text, the break, and the second line. You can use that expression as the first argument to MsgBox, which is the prompt. The other arguments are optional and can set the dialog’s buttons and title.

Before running any sample macro, save a copy of the workbook. VBA macros cannot be undone with Ctrl+Z, even when they appear to make only a small change.

A complete two-line example

This standalone procedure shows the basic pattern. In Excel for Microsoft 365 on Windows, open the Visual Basic Editor, insert a standard module, and put the procedure there. Run it to display the message box.

Sub ShowTwoLines()
    ' Join two prompt strings with a Windows-style line break.
    Dim prompt As String

    prompt = "The report is ready." & vbCrLf & "Check the totals before sending it."
    MsgBox prompt, vbInformation, "Report status"
End Sub

The first argument is the prompt text, vbInformation selects an information icon, and "Report status" is the title shown in the dialog’s title bar. The icon and title do not control the line break; only the prompt string does. If you do not need a named variable, you can put the joined text directly in the MsgBox call.

Add blank lines and organize a longer message

One line break moves to the next line. Two consecutive line breaks leave an empty line between blocks, which can make a message easier to scan. Use the same string-joining pattern for labels and values:

Sub ShowImportSummary()
    ' Show a short summary with a blank line between its sections.
    Dim rowsAdded As Long
    Dim prompt As String

    rowsAdded = 24
    prompt = "Import complete." & vbCrLf & vbCrLf & _
             "Rows added: " & CStr(rowsAdded) & vbCrLf & _
             "Review the output sheet for any warnings."
    MsgBox prompt, vbInformation, "Import result"
End Sub

Here, the two adjacent vbCrLf values after the opening sentence create the blank line. The underscore at the end of the first assignment line is VBA’s explicit line-continuation character: it lets the source code continue on the next physical line. It does not add a line break to the message. In VBA, leave a space before the underscore, and do not put a comment after it on the same line.

Choose between vbCrLf, vbNewLine, and other breaks

vbCrLf is a common, clear choice for MsgBox prompts in Windows VBA. It represents the two-character sequence carriage return plus line feed. The built-in vbNewLine constant represents a newline appropriate to the platform, so it can be useful when code is intended to run on more than one operating system. For an ordinary Excel macro on Windows, either is usually suitable; using one convention consistently keeps the code easy to read.

VBA also provides vbLf for a line feed and vbCr for a carriage return alone. These can matter when working with text that comes from another source, but are not usually the clearest choice for a newly constructed Windows message. Excel worksheet cells commonly store an in-cell line break as a line feed, so text copied from a cell may not use the same newline sequence as a prompt you build yourself. If a sourced message displays unexpectedly, check what line-ending characters it contains and normalize them to the format your prompt needs.

You can also create characters with functions such as Chr, but that is rarely necessary here. For example, a carriage return and line feed can be written as Chr(13) & Chr(10). The named constant vbCrLf communicates the intent more directly and avoids making readers remember the character codes.

Build prompts from variables safely

Messages often combine fixed wording with values calculated by a macro. Join each piece with &, and place vbCrLf exactly where the display should move to a new line. Convert numbers to text when doing so makes the code’s intent clear; CStr converts a value to a string. Dates and currency may need explicit formatting, because a basic conversion may not present them in the exact style you want.

For a date, for example, use Format to control the displayed text, then join the result into the prompt. Keep the labels understandable and avoid relying on spaces to line up columns: fonts and dialog sizing can make space-based alignment look uneven. If a value may be blank, very long, or contain a line break of its own, account for that when designing the message. An unexpected newline inside a value can make a tidy two-line prompt appear to have extra sections.

It is also good practice to keep the message assembly separate from the display call when the prompt has several parts. A named String variable is easier to inspect in the editor, and you can set a breakpoint or examine the variable before showing it. That makes it simpler to distinguish a problem in the text from a problem in the MsgBox arguments.

Control the dialog title, buttons, and response

A line break changes only the prompt layout. To make the dialog more useful, you can also provide a title and choose buttons or an icon. For example, vbYesNo displays Yes and No buttons, while vbQuestion selects a question icon. When the user’s choice matters, capture the return value rather than treating the dialog as a display-only message.

Sub ConfirmClosing()
    ' Ask for a choice and respond to the returned button value.
    Dim answer As VbMsgBoxResult
    Dim prompt As String

    prompt = "The workbook has unsaved changes." & vbCrLf & _
             "Do you want to continue closing?"
    answer = MsgBox(prompt, vbYesNo + vbQuestion, "Confirm close")

    If answer = vbYes Then
        MsgBox "Continue with the close process."
    Else
        MsgBox "Keep the workbook open."
    End If
End Sub

The result is stored as a VbMsgBoxResult, and comparing it with vbYes or vbNo makes the choice explicit. Constants for buttons and icons can be combined with a plus sign, as shown. A line break in a confirmation prompt is useful for separating context from the actual question, but the wording should still make the consequence of each choice clear.

Common line-break problems and fixes

  • The text appears on one line: Check that vbCrLf is inside the prompt expression and joined between the two text strings with &. Typing the characters \n in a VBA string does not create a newline as it does in some programming languages.
  • VBA reports a syntax error: Check the quotation marks around each text fragment and confirm that every & and line-continuation underscore is in the right place. A missing quote can make a correct-looking line break expression fail to compile.
  • The prompt has a strange extra gap: Look for two line-break constants where only one was intended, or for a value that already contains a newline. Two breaks create a blank line by design.
  • A long prompt is hard to read: Break it into short labeled sections, remove unnecessary detail, and consider whether a dialog is the right interface. A MsgBox is not a resizable report window, so a large block of text can be awkward to navigate.

When debugging, temporarily assign the prompt to a variable and inspect its contents before displaying it. This helps reveal whether the text was assembled correctly. Also distinguish a VBA editor line continuation, written as a space and underscore at the end of a code line, from a displayed newline, represented by a value such as vbCrLf. They solve different problems.

When MsgBox is not the right tool

MsgBox works well for brief alerts, simple confirmations, and small summaries. It is less suitable for lengthy instructions, data that needs scrolling, or information the user must edit. Adding more line breaks does not add scrolling or make the dialog resizable. For a more involved interaction, a VBA UserForm can provide labels, text boxes, buttons, and other controls arranged for the task. For a report, writing the information to a worksheet may be clearer and easier to keep for later reference.

VBA macros run in desktop Excel, not Excel for the web. Excel for Mac also supports VBA in its desktop application, although available macro features and platform behavior can differ from Windows. If the same procedure must run on Windows and Mac, vbNewLine communicates platform-neutral intent, but test the complete macro in the environments you support. The basic method—joining prompt text with a newline constant—remains the important idea.

Frequently Asked Questions

What is the VBA code for a new line in a MsgBox?
Join the text fragments with & vbCrLf &, such as "Top" & vbCrLf & "Bottom". That puts Bottom on the line below Top.

How do I leave a blank line in a VBA message box?
Use two line breaks in succession: "First section" & vbCrLf & vbCrLf & "Second section". The second break creates the empty line between the sections.

Can I use vbNewLine instead of vbCrLf?
Yes. vbNewLine is a platform-appropriate newline constant and is a reasonable choice for code intended to be portable. vbCrLf is a familiar explicit choice for Windows VBA.

Why does \n not work in my VBA MsgBox?
VBA does not use the backslash-n escape sequence for a newline. Use a VBA newline constant such as vbCrLf and join it into the prompt with &.

Can a MsgBox show more than two lines?
Yes. Add more text fragments and newline constants to the prompt. Keep the message concise, though: MsgBox is intended for short interactions, and a long message can be difficult to read in a fixed dialog.

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.