Excel VBA MsgBox Carriage Return: Line Breaks Explained

VBA & macros · Updated November 21, 2026

To put a carriage return and line break in an Excel VBA MsgBox, join the message parts with vbCrLf, as in MsgBox "First line" & vbCrLf & "Second line". The constant inserts a new line in the displayed message; it does not merely wrap text at the edge of the dialog.

What vbCrLf Does in a MsgBox

A MsgBox displays a string supplied by your VBA code. In Windows text, a conventional new line consists of two control characters: carriage return (CR) and line feed (LF). VBA’s built-in constant vbCrLf represents that pair. Concatenate it between pieces of text to start the next piece on a new line.

The ampersand (&) joins strings. The example below stores the prompt first, then displays it. Before running any macro, save a copy of the workbook: VBA macros cannot be undone with Ctrl+Z. This simple example only displays text, but the copy reminder is important for macros that change workbook data.

Sub ShowTwoLines()
    Dim prompt As String

    ' Join the two message lines with a Windows-style line break.
    prompt = "The report is ready." & vbCrLf & "Select OK to continue."
    MsgBox prompt, vbInformation, "Report status"
End Sub

In the dialog, “The report is ready.” and “Select OK to continue.” appear on separate lines. A single vbCrLf creates one break; use it again wherever another line should begin. The message box may also wrap a long line automatically if it does not fit, but automatic wrapping is different from a deliberate line break in your string.

How to Add a Line Break in VBA Code

In Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, then choose Insert > Module and paste a procedure into the module. Press F5 with the cursor in the procedure to run it, or return to Excel and run it through Developer > Macros. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon and select Developer. On a Mac, use Option+F11 (on some keyboards, Fn may also be needed) to open the editor; ribbon labels and keyboard behavior can vary slightly. VBA macros do not run in Excel for the web.

When building a longer message, put each logical line in the string where it is easiest to read. This version adds a blank line between a heading and details by using two line breaks consecutively:

Sub ShowSummary()
    Dim prompt As String

    ' A repeated break leaves one empty line between sections.
    prompt = "Import complete" & vbCrLf & vbCrLf & _
             "Rows added: 18" & vbCrLf & _
             "Rows skipped: 2"
    MsgBox prompt, vbInformation, "Import summary"
End Sub

The underscore is VBA’s explicit line-continuation character. It makes one VBA statement span multiple lines in the editor; it is not itself a displayed line break. The visible breaks in this example come from vbCrLf. A space must appear before the continuation underscore, and no comment can follow the underscore on that same line.

Choosing vbCrLf, vbNewLine, vbCr, or vbLf

For a MsgBox intended for Windows, vbCrLf is the clearest common choice. VBA also provides vbNewLine, a newline constant that is convenient when you want code to use the platform’s newline convention. In many Excel VBA situations they produce the expected new paragraph, but using vbCrLf makes the CR-plus-LF pair explicit and familiar to readers of Windows VBA code.

  • vbCrLf: carriage return followed by line feed; a reliable, readable choice for Windows MsgBox prompts.
  • vbNewLine: a newline constant useful for code intended to use the host platform’s convention.
  • vbCr: carriage return only. It is not the usual choice for a Windows message line break.
  • vbLf: line feed only. It can work in some text contexts, but may behave differently in controls or applications that expect CRLF.

You can also write Chr(13) & Chr(10), where 13 is CR and 10 is LF. That is valid, but it is less readable than vbCrLf and offers no advantage for an ordinary MsgBox. If you are exchanging text with another application or processing files, that application may require a particular newline convention; choose according to the recipient rather than assuming every system treats all three forms identically.

Combining Text, Variables, and Blank Lines

A MsgBox prompt can combine fixed text with values from cells or variables. Keep each value’s formatting in mind: a date, currency amount, or number may need formatting before you concatenate it. When using a range value, read it into a variable or refer to the cell explicitly, and make sure the referenced sheet and cell are the ones you intend. The line-break constant works the same whether the neighboring text is literal or variable content.

Sub ShowCellStatus()
    Dim prompt As String
    Dim itemName As String
    Dim itemCount As Long

    ' Read example values from the active sheet.
    itemName = CStr(ActiveSheet.Range("A2").Value)
    itemCount = CLng(ActiveSheet.Range("B2").Value)

    prompt = "Item: " & itemName & vbCrLf & _
             "Count: " & CStr(itemCount)
    MsgBox prompt, vbInformation, "Current record"
End Sub

Here the expected layout is a name or item label in A2 and a whole-number count in B2 on the active worksheet. For example, if A2 contains “Folders” and B2 contains 12, the dialog shows those values on two lines. The conversion functions help make the intended string conversion explicit. If B2 is blank, contains text that is not a number, or contains an error value, CLng can raise an error; validate input when workbook data is not guaranteed to be clean.

For a more elaborate message, construct it in stages instead of placing a very long expression in one line. That makes punctuation and line breaks easier to inspect. It also helps avoid accidentally joining words without a space: a line break does not add spaces before or after the adjacent text.

Common Carriage-Return Problems

If the message appears on one line, check that the code actually concatenates the newline constant into the prompt. Typing the characters vbCrLf inside quotation marks creates ordinary visible text, not a line break. For example, "First line vbCrLf Second line" displays the constant’s name as text. The correct pattern closes the first string, joins the constant with &, and then joins the next string.

  • Missing concatenation: Use & vbCrLf & between the text pieces.
  • Wrong quotation marks: Keep the constant outside the quoted text. Straight quotation marks delimit VBA strings.
  • Confusing source layout with output: Pressing Enter in the editor starts another line of code, not another line in the MsgBox prompt. Use vbCrLf in the string.
  • Only one newline character: If a particular display context handles vbLf or vbCr unexpectedly, try the conventional vbCrLf pair.
  • Unexpected extra blank lines: Two consecutive vbCrLf constants intentionally leave an empty line. Remove one if the gap is too large.

There is also a difference between an intentional newline and word wrapping. A long sentence can wrap onto another visual row based on the dialog’s width, even without a newline. Conversely, a short line will remain separate when you insert vbCrLf. If precise alignment matters, remember that proportional fonts and dialog sizing make spaces an unreliable way to create columns; use a worksheet or a form for structured tabular information.

MsgBox Buttons, Titles, and the Returned Choice

The general syntax is MsgBox(prompt, buttons, title). The prompt is where the line break belongs. The optional buttons argument controls which buttons and icon appear, while the optional title sets the caption. You can use built-in constants such as vbYesNo and vbQuestion together, but a line break in the prompt does not change the buttons or the returned result.

When users need to choose an action, capture the return value and compare it with a named constant. For example, the following displays a two-line question and then reports the selection in the Immediate window in the Visual Basic Editor:

Sub AskBeforeContinuing()
    Dim answer As VbMsgBoxResult
    Dim prompt As String

    ' Ask a question with a deliberate line break.
    prompt = "Continue with the update?" & vbCrLf & _
             "Choose Yes to proceed."
    answer = MsgBox(prompt, vbYesNo + vbQuestion, "Confirm update")

    If answer = vbYes Then
        Debug.Print "User chose Yes"
    Else
        Debug.Print "User chose No"
    End If
End Sub

This example does not update data; it only illustrates how the answer can be handled. In a real macro, put the consequential action inside the appropriate branch and provide a safe cancel or “No” path. A MsgBox is modal, meaning the user must respond to it before continuing with the code that called it.

MsgBox Line Breaks Versus Worksheet Line Breaks

A line break in a MsgBox is not the same as a line break inside an Excel cell. MsgBox uses a VBA string, so vbCrLf separates message lines. In a worksheet cell, a newline is part of the cell’s text and may require Wrap Text to show on multiple lines. For manual entry in Excel on Windows, Alt+Enter inserts a line break while editing a cell. On Mac, the shortcut is Control+Option+Return in many Excel configurations; check the keyboard shortcuts for your installed version if that combination is intercepted by macOS.

Similarly, pressing Enter in a VBA code window does not insert a break into a string literal. VBA’s editor has its own syntax for continuing statements across source lines, while the string itself needs a newline character. If you want to transfer text from a cell into a MsgBox and preserve its existing line breaks, test the actual cell content, particularly if it came from an imported file. Imported text may use different newline characters, and its display can also depend on the destination.

Platform and Macro Availability

These examples target desktop Excel for Microsoft 365 on Windows. Excel for Mac supports VBA and the same basic MsgBox approach; vbCrLf is a standard VBA constant, so it is generally suitable for messages shown in Excel on either desktop platform. Differences in editor shortcuts, menu placement, and some other VBA features can matter, but the basic string concatenation shown here does not require a Windows-only API.

Excel for the web does not run VBA macros. A workbook containing VBA can be opened there, but to execute this code, open it in desktop Excel with macros permitted by your organization’s security settings. A workbook with VBA should be saved in a macro-enabled format such as .xlsm if you need to retain the code. Do not enable macros in an untrusted file simply to view its contents; follow your organization’s security guidance.

Frequently Asked Questions

How do I add a new line in an Excel VBA MsgBox?
Join the message text with vbCrLf, for example, "First" & vbCrLf & "Second". The two text parts display on separate lines.

Is vbCrLf the same as vbNewLine?
They are both newline constants, but vbCrLf explicitly represents carriage return plus line feed. It is a clear conventional choice for Windows MsgBox text; vbNewLine expresses a platform newline.

Why does my MsgBox show vbCrLf instead of making a new line?
It is probably inside quotation marks. Write & vbCrLf & between separately quoted text strings so VBA evaluates the constant rather than displaying its name.

Can I add a blank line to a MsgBox?
Yes. Put two newline constants together between sections, such as "Heading" & vbCrLf & vbCrLf & "Details". One extra break creates the empty row.

Does a MsgBox carriage return work in Excel for the web?
No, because Excel for the web does not execute VBA macros. Run the macro in desktop Excel for Windows or Mac, subject to macro security settings.

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.