VBA Newline in MsgBox: Add Line Breaks

VBA & macros · Updated November 18, 2026

To add a newline in a VBA MsgBox, join the text with vbCrLf, for example: MsgBox "First line" & vbCrLf & "Second line". The message box displays the two text parts on separate lines; for several lines, insert the constant between each part.

The simplest way to add a line break

In VBA, a message box’s prompt is a string. The ampersand (&) joins string pieces together, and vbCrLf supplies a line break between them. A complete Excel macro can look like this:

Sub ShowTwoLines()
    ' Display two separate lines in a message box.
    Dim messageText As String

    messageText = "The report is ready." & vbCrLf & "You can continue."
    MsgBox messageText, vbInformation, "Status"
End Sub

The first argument to MsgBox is the prompt. The optional second argument chooses buttons and an icon; vbInformation requests an information icon. The optional third argument is the title shown in the dialog’s title bar. None of those optional arguments changes how the newline is made.

Before running a macro that changes a workbook, save a copy: VBA macros cannot be undone with Ctrl+Z. This example only displays a dialog, but the same precaution matters when adapting code to edit cells or other workbook content.

What vbCrLf means

vbCrLf is a built-in VBA constant representing a carriage return followed by a line feed. That pair is the conventional Windows line ending, and it is the clearest, most familiar choice for separating lines in a Windows Office message box. You do not need to look up or type the character codes yourself.

Other related constants are vbCr, for a carriage return, and vbLf, for a line feed. VBA also provides vbNewLine, which represents a platform-appropriate newline. For ordinary MsgBox prompts, vbCrLf is a reliable, explicit choice; vbNewLine is useful when you want to express the intent of “start a new line” without specifying the characters.

Use one separator for each break you want. A string with no separator remains one continuous line, subject to the dialog’s own wrapping. A separator creates a deliberate new line even if the text before it would otherwise fit across the dialog.

Writing messages with several lines

For a short prompt, joining literal text directly in the MsgBox call is readable. For a longer message, build it in a variable first so the line structure is easy to inspect and revise:

Sub ShowChecklist()
    ' Build a short checklist with one item per line.
    Dim messageText As String

    messageText = "Before closing the workbook:" & vbCrLf & _
                  "- Save your changes" & vbCrLf & _
                  "- Check the totals" & vbCrLf & _
                  "- Send the final copy"

    MsgBox messageText, vbInformation, "Checklist"
End Sub

The space and underscore at the end of each continued VBA statement tell the editor that the statement carries on on the next source-code line. They are for organizing the code; they do not add visible line breaks to the message. The visible breaks come from the vbCrLf values inside the string expression.

In this example, the message has four visible lines: a heading and three checklist items. If you want a blank line between the heading and the list, insert an additional vbCrLf at that point. Two consecutive newline constants create one empty line between the surrounding text.

Adding a blank line or a variable value

A blank line is simply an empty line between two line breaks. To put one between a heading and a detail, join the heading, two newline constants, and the detail. The same technique works when some of the message is stored in variables, such as a worksheet value or a calculated result.

Sub ShowNamedMessage()
    ' Add a worksheet value to a multi-line prompt.
    Dim itemName As String
    Dim messageText As String

    itemName = ThisWorkbook.Worksheets("Sheet1").Range("A2").Value
    messageText = "Review this item:" & vbCrLf & vbCrLf & itemName

    MsgBox messageText, vbInformation, "Review"
End Sub

With Sheet1!A2 containing “Quarterly summary,” the prompt shows “Review this item:” followed by a blank line and then “Quarterly summary.” If the cell is empty, the final line will also be empty. When that would be confusing, check the value before constructing the message and display a suitable fallback such as “(no name entered).”

For messages assembled from a list or loop, add a newline only between entries or remove an unwanted final newline after building the text. A trailing break often looks like an unexplained blank line at the bottom of the dialog. Being intentional about separators makes the result easier to read.

Choosing between vbCrLf, vbNewLine, and Chr

For a normal MsgBox prompt, choose vbCrLf when you want an explicit Windows-style line ending. Choose vbNewLine when platform-neutral intent is more important than naming the exact characters. Both are built-in constants, so neither needs a declaration or a reference to an external library.

You may also see code written as Chr(13) & Chr(10). Those character codes correspond to carriage return and line feed, so the expression can create the same Windows pair as vbCrLf. The constant is generally easier to read and less likely to be mistyped. Using only Chr(10) or only Chr(13) can behave differently across controls and contexts; prefer the named newline constant unless you have a specific reason to handle the characters yourself.

Do not confuse a newline in a MsgBox with wrapping. A long line may wrap automatically when it reaches the dialog’s available width, but that is different from inserting a controlled break. Use a newline when you need the next item, label, or instruction to begin on a new line regardless of wrapping.

Common problems and how to fix them

  • The text shows the characters “vbCrLf.” Check that you are joining the constant outside the quoted text. "First line vbCrLf Second line" contains those letters literally; "First line" & vbCrLf & "Second line" inserts a break.
  • VBA reports a syntax error. VBA string literals use straight double quotes and cannot be split across source lines just by pressing Enter. Close the string, join the next part with &, and use the space-underscore line continuation if you want to continue the statement on another code line.
  • The dialog still looks like one paragraph. Confirm that the message is actually being built with a newline constant and that the code passes that variable as the first argument to MsgBox. Also check whether the text is wrapping naturally; wrapping alone does not prove that a hard line break was inserted.
  • There is an extra empty line. Each newline adds a break. Remove one repeated constant if you did not intend a blank line, or check whether a loop adds a separator after its final item.
  • Some text is missing or oddly joined. Inspect the concatenation around each variable and separator. Every part must be joined with &; a missing operator can cause a compile error, while a misplaced quote can turn a constant into ordinary text.

When debugging, temporarily assign the prompt to a clearly named string variable and inspect the expression one section at a time. This is usually simpler than trying to decipher a long MsgBox call containing many quoted fragments and separators.

Formatting the dialog and its buttons

Line breaks control the prompt’s layout, not the dialog’s full appearance. The optional Buttons argument controls which buttons and icon are shown, and the optional Title argument sets the title bar text. For example, vbYesNo + vbQuestion requests Yes and No buttons with a question icon. The user’s response is returned by MsgBox, so code can act on it.

Here is a confirmation example that keeps the question on separate lines and checks the response:

Sub ConfirmClose()
    ' Ask before continuing and check the selected button.
    Dim answer As VbMsgBoxResult
    Dim messageText As String

    messageText = "The draft has not been reviewed." & vbCrLf & _
                  "Continue anyway?"

    answer = MsgBox(messageText, vbYesNo + vbQuestion, "Confirm")

    If answer = vbYes Then
        MsgBox "Continuing.", vbInformation, "Status"
    End If
End Sub

The VbMsgBoxResult variable makes the result’s purpose clear. The line break affects only the question displayed to the user; it does not change how the buttons work or which value the function returns. Avoid using a message box as the only way to present a large report: a compact prompt is easier to scan, while a worksheet or user form is better suited to extensive content or several decisions.

Using the code in Excel on Windows or Mac

In Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11, insert a standard module through Insert > Module, and paste a complete procedure into that module. Run the procedure from the editor with the cursor inside it, or run it through Excel’s macro tools. Save a macro-enabled workbook as .xlsm if you need to keep VBA code in the file; a regular .xlsx workbook does not store VBA macros.

Excel for Mac also supports VBA and the same basic MsgBox syntax. The Visual Basic Editor can be opened from Tools > Macro > Visual Basic Editor; the keyboard shortcut can vary with the Mac keyboard and function-key settings, so the menu route is a dependable alternative. Use a macro-enabled workbook format to retain the code on Mac as well. The examples use standard VBA constructs rather than Windows-only APIs, though a workbook that includes other platform-specific code may need separate changes.

Macro security settings can affect whether a procedure is allowed to run. Enable macros only for files you trust, and follow your organization’s security policy. A message box that only displays text does not need access to external services, but a larger macro may perform other actions that deserve review before you run it.

Frequently Asked Questions

How do I add a new line in a VBA MsgBox?
Join the text on either side of the break with vbCrLf: MsgBox "Line one" & vbCrLf & "Line two". Add another constant wherever another line should start.

Can I use vbNewLine in a MsgBox?
Yes. vbNewLine is a built-in VBA newline constant and can be concatenated into the prompt just like vbCrLf. For Windows-only Office code, vbCrLf is an explicit, common choice.

How do I put a blank line in a message box?
Use two newline constants in succession between the text sections, such as "Heading" & vbCrLf & vbCrLf & "Details". That leaves one empty line between the heading and details.

Why does vbCrLf appear as text instead of making a new line?
It is probably inside quotation marks. A constant inside a quoted string is literal text. Close the quoted text before the constant, concatenate with &, and then concatenate the next quoted section.

Can a MsgBox show formatted text or a long report?
A MsgBox supports line breaks and standard button and icon choices, but it is not a general rich-text editor. For long content, extensive formatting, or multiple fields, present the information in a worksheet or a VBA user form 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.