To put a new line in an Excel VBA message box, join the text with vbCrLf: MsgBox "First line" & vbCrLf & "Second line". The constant inserts a line break between the two parts of the prompt; use it again wherever the message should continue on another line.
How a MsgBox line break works
A VBA message box displays its prompt as a string. To make multiple lines, build that string from text fragments and a newline character. The ampersand (&) joins the fragments, while vbCrLf supplies the line break. This is different from pressing Enter while typing inside a VBA string: a quoted string cannot simply continue onto a new code line that way.
Here is a complete example you can run from a standard module:
Sub ShowMultilineMessage()
Dim prompt As String
' Join three lines in the message-box prompt.
prompt = "The report is ready." & vbCrLf & _
"Rows processed: 25" & vbCrLf & _
"Check the Results sheet."
MsgBox prompt, vbInformation, "Processing complete"
End Sub
The underscore at the end of the first two assignment lines is VBA’s explicit line-continuation character. It makes the source code easier to read; it does not create a line break in the displayed message. The displayed breaks come from vbCrLf. In modern VBA, leave a space before the underscore, and do not put a comment after it on the same line.
Choosing vbCrLf, vbNewLine, or Chr
For a typical Excel VBA message box on Windows, vbCrLf is a clear, familiar choice. It represents a carriage return followed by a line feed, the conventional Windows newline. VBA also provides vbNewLine, a platform-oriented newline constant. It can be useful when writing VBA intended to run on more than one operating system. In a simple message-box prompt, either is commonly used to separate lines.
You may also see Chr(13) & Chr(10), which constructs the same carriage-return-and-line-feed pair explicitly. That can be useful when reading older code, but the named constant is easier to understand. Chr(10) alone is a line feed, and Chr(13) alone is a carriage return. They are not interchangeable in every Windows text context, so use the pair or a named newline constant rather than guessing.
- Use
vbCrLffor an explicit Windows-style line break in ordinary Excel VBA. - Use
vbNewLinewhen you want VBA’s platform-specific newline constant. - Use
Chr(13) & Chr(10)when you need to make the underlying characters explicit.
Do not confuse the newline constant with a line break in the VBA editor. A line break in the editor affects how the code is laid out; a newline included in the prompt string affects what the user sees.
Adding breaks to longer or conditional messages
For a longer message, keep the text in a variable and add each line deliberately. This makes the order and spacing easier to review, and it lets you add information only when it applies.
Sub ShowStatusMessage()
Dim prompt As String
Dim itemCount As Long
' Example value; replace it with the count your macro calculates.
itemCount = 12
prompt = "Import finished." & vbCrLf & _
"Items imported: " & itemCount
If itemCount = 0 Then
prompt = prompt & vbCrLf & "No rows were added."
End If
MsgBox prompt, vbInformation, "Import status"
End Sub
In this example, itemCount is converted to text as VBA joins it to the string. If the count is zero, the conditional block appends a third line. You can use the same pattern for worksheet names, dates, or a short list of issues. Keep in mind that a message box is best for a brief, readable summary; a very long report is usually easier to review in a worksheet or a UserForm.
When assembling a list, add the newline between entries, not after every entry automatically. Otherwise, the final line may be followed by a blank line. A deliberate trailing break is not necessarily an error, but it can make the message appear to have extra empty space.
Using the MsgBox title and buttons
The line break belongs in the first argument to MsgBox, called the prompt. The optional second argument controls the buttons and icon, and the optional third argument is the title shown in the message-box title bar. For example, vbInformation displays an information icon; it does not add a new line. The title is separate from the prompt, so adding vbCrLf to the title argument will not create another line in the message body.
A message box can also return a value when a user selects a button. For example, a Yes/No prompt can be checked with vbYesNo, and the result compared with vbYes. This is useful when the next action depends on the user’s choice, but it does not change how prompt line breaks work. Keep the prompt, button options, and title in their correct argument positions, or use named arguments for clarity in more complex calls.
For a plain informational message, the basic form is MsgBox prompt, vbInformation, "Status". If the message does not need a special icon or title, a single prompt argument is enough. Choose buttons that match the action: a message that only reports success generally does not need a Yes/No choice.
Common problems and how to fix them
- The code shows the characters instead of breaking the line. Check that the newline is outside the quoted text. Use
"First" & vbCrLf & "Second", not"First vbCrLf Second"; in the latter, VBA treats the letters as ordinary text. - There is no space between words at the break. A newline does not add punctuation or explanatory wording. Put the intended text in each fragment and add a space where needed if the sentences continue across lines.
- The editor reports a syntax error. Check that each text fragment has paired straight quotation marks, each ampersand is in place, and any continued code line ends with a space and underscore. Curly “smart quotes” copied from a document are not VBA string delimiters.
- The line break appears in the wrong place. Each newline belongs exactly where it appears in the concatenation. Read the expression from left to right, or build the prompt one assignment at a time to see which fragment introduces the unexpected break.
- The message looks crowded or gets cut off. Break long text into shorter lines and trim unnecessary detail. Message-box layout depends on the text and the system’s display environment; do not rely on a particular line width or use a MsgBox as a substitute for a large report.
- The macro does not run. VBA macros do not run in Excel for the web. In desktop Excel, check that the file is saved in a macro-enabled format such as
.xlsmand that the macro is permitted by the workbook’s security settings.
Also distinguish a blank line from a regular line break. Two consecutive newline constants create an empty line between text fragments: "First" & vbCrLf & vbCrLf & "Second". Use that spacing sparingly so the message remains compact.
Where to write and run the VBA
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 the cursor inside the procedure by pressing F5. You can also use Developer > Visual Basic to open the editor. If the Developer tab is not visible, it can be enabled in Excel Options under Customize Ribbon.
In Excel for Mac, use Tools > Macro > Visual Basic Editor or the Visual Basic command on the Developer tab; the available keyboard shortcut can depend on the Mac keyboard and function-key settings. On some keyboards, you may need to include the Fn key when using a function-key shortcut. Excel for the web can open and edit many workbooks, but it cannot create, edit, or run VBA macros; use the desktop app for this code.
Before running a macro that changes workbook data, save a copy of the workbook. Excel’s Undo command, including Ctrl+Z on Windows, cannot undo actions performed by a VBA macro. The examples above only display a message, but this is an important habit for procedures that also edit cells, delete data, or change workbook structure.
When a MsgBox is not the right display
A MsgBox is a small, temporary dialog suited to a confirmation, a short status, or a concise warning. Its user cannot conveniently copy and work with a long list of results, and the dialog interrupts the workflow until dismissed. If your message needs many lines, consider writing the details to a worksheet, using a UserForm with a text box, or showing a compact summary in the message box with a reference to where the full details are stored.
For example, a macro that finds dozens of validation issues can put the issue list on a dedicated worksheet and show a short MsgBox such as “Validation finished” followed by the number of issues and the sheet name. That gives the user a quick signal without turning a transient dialog into a hard-to-read report. A UserForm is more appropriate when the user needs to interact with multiple controls or review a larger block of text.
Frequently Asked Questions
What is the simplest way to add a new line in a VBA MsgBox?
Join the text fragments with vbCrLf, for example: MsgBox "Line one" & vbCrLf & "Line two".
Can I use vbNewLine instead of vbCrLf?
Yes. vbNewLine is VBA’s platform-specific newline constant and is a reasonable choice for code intended to run across platforms. vbCrLf is also widely used for Windows Excel VBA.
How do I make a blank line in a MsgBox?
Put two newline constants together between the text fragments: "First paragraph" & vbCrLf & vbCrLf & "Second paragraph". The empty line is the space between those two breaks.
Why does MsgBox show vbCrLf as text?
The constant is probably inside quotation marks. Keep the quotes around the text only, then concatenate the constant outside them: "First" & vbCrLf & "Second".
Can a VBA MsgBox show multiple lines in Excel for the web?
No. Excel for the web does not run VBA macros. Open the workbook in desktop Excel for Windows or Mac to run a VBA MsgBox.
Can I add a line break to the MsgBox title?
The title is a separate argument from the prompt and is intended as a short caption. Put the line breaks in the prompt string, not in the title, if you want multiple lines in the message body.
Related
- Excel Not Responding? Causes and Fixes
- Excel Not Responding? Recover Files and Find Temp Data
- Excel Not Responding in Safe Mode? Causes and Fixes
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Find Position of a Substring in a StringIn VBA, use InStr to find a substring’s position within a string: it returns the position of the…
- Excel VBA Copy and Paste Formatting Without Changing ValuesTo copy formatting with Excel VBA without copying cell values or formulas, copy the source range and paste…
- VBA Macro Error Handling: Patterns, Examples, and FixesVBA macro error handling lets a procedure respond to runtime problems instead of stopping without explanation. Use On…
- VBA Add Worksheet After the Last SheetTo add a worksheet after the last sheet tab in Excel, use Worksheets.Add with the last item in…
- Copy Paste Values in Excel VBA: Methods and ExamplesTo copy a range’s results—not its formulas—in Excel VBA, use Copy followed by PasteSpecial Paste:=xlPasteValues. For a quick…
- Delete Table Row in VBA: Excel Examples and TipsTo delete a row from an Excel table with VBA, use the table’s ListRows collection: identify the table…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.