Excel VBA MsgBox Line Break: Step-by-Step Guide
In this article
To put a line break inside an Excel VBA MsgBox, join your text with the built-in constant vbCrLf (or vbNewLine) using the concatenation operator &, then pass the result to MsgBox. For example: MsgBox "Line one" & vbCrLf & "Line two". That single line of code displays two lines in the popup. Everything below explains the exact syntax, how to control the icon and title at the same time, and the mistakes that make the break disappear.
What You'll Need
- Microsoft Excel on Windows or Mac (the VBA editor is included in the desktop app; it is not available in Excel for the web).
- Macro security set to allow macros, or a workbook saved as
.xlsmif you want to keep the code. - Basic familiarity with opening the VBA editor: press Alt+F11 on Windows, or on Mac use Tools > Macro > Visual Basic Editor from the Excel menu.
Step-by-Step
- Open the VBA editor. In Excel, press Alt+F11 (Windows) or choose Tools > Macro > Visual Basic Editor (Mac). Menu labels can differ slightly by version and region, so look for the Visual Basic or Macro entry if the exact wording is not there.
- Insert a module. In the editor, choose Insert > Module. A blank code window appears. You can also double-click ThisWorkbook or a sheet in the Project pane, but a standard module keeps the macro easy to find.
- Start a Sub procedure. Type
Sub ShowMessage()and press Enter. The editor addsEnd Subautomatically. - Write the simplest two-line message. Between the Sub and End Sub lines, type:
MsgBox "First line" & vbCrLf & "Second line"
The ampersand joins the text and the constant into one string.vbCrLfmeans carriage return plus line feed, which is what Windows dialogs expect. - Run it. Press F5 with the cursor inside the procedure, or click the green Run button. A message box appears with the two lines stacked. Click OK to return to the editor.
- Add a title and an icon. Use the full syntax:
MsgBox Prompt, Buttons, Title. For example:MsgBox "Backup complete" & vbCrLf & "Check the log file", vbInformation, "Status"
The prompt is the text with the break,vbInformationsets the icon, and"Status"is the window title. If you omit the title, Excel shows the application name instead. - Build longer messages from variables. Concatenation works the same with cell values:
MsgBox "Customer: " & Range("A1").Value & vbCrLf & "Total: " & Range("B1").Value. Each& vbCrLf &starts a new line. - Use a line-continuation character for readability. Long prompts can be split across code lines with a space and underscore at the end:
MsgBox "Line one" & vbCrLf _then on the next line& "Line two". This changes nothing in the output; it only makes the code easier to read. - Save the workbook as macro-enabled. Use File > Save As and choose Excel Macro-Enabled Workbook (
.xlsm). A normal.xlsxfile discards the module when closed.
Common Mistakes
- Typing the break as literal text. Writing
"Line one\nLine two"or"Line one <br> Line two"shows the characters instead of breaking the line. VBA has no escape sequence inside a string for a newline; you must concatenatevbCrLfoutside the quotes. - Putting vbCrLf inside the quotes.
"vbCrLf"is a six-character word, not the constant. It must sit between ampersands:"text" & vbCrLf & "text". - Missing an ampersand.
"Line one" vbCrLf "Line two"causes a compile error. Every piece of the string needs to be joined. - Using a line break as the title argument. The Title parameter is a single-line caption; breaks there are ignored or truncated. Keep breaks in the prompt only.
- Assuming the break is visible in the Immediate window. If you test with
Debug.Print, the break appears as separate output lines, which can look like nothing happened. Test with the actual MsgBox. - Forgetting Mac differences. The VBA editor and MsgBox exist on Mac Excel, but very long prompts can be clipped by the dialog width. Keep each line reasonably short.
Tips
vbCrLfandvbNewLinebehave the same in a MsgBox on Windows.vbCrLfis the conventional choice.- Use
Chr(10)only when you specifically need a bare line feed; for a standard Excel message box,vbCrLfis the safe default. - Keep prompts to a few short lines. A message box does not scroll, so a very long prompt can run off screen or be clipped.
- Combine constants with
+when you need an icon and buttons together, for examplevbYesNo + vbQuestion. - Store repeated messages in a string variable first, then pass the variable to MsgBox. It is easier to edit and reuse.
- If you need richer formatting, such as bold text or multiple paragraphs, a MsgBox cannot do it; use a small UserForm with a label instead.
Troubleshooting
If the message box shows one long line, check that vbCrLf is outside the quotation marks and joined with & on both sides. If you get a compile error, look for a missing ampersand or an unclosed quote. If the macro does not run at all, confirm macros are enabled and the file is saved as .xlsm. If the box appears but the title is wrong, remember the arguments are positional: prompt, buttons, title, so a missing buttons argument shifts the title. If the text is cut off, shorten the lines or split the message into two boxes. On a shared or locked-down machine, macro settings may block the code entirely; check with whoever manages the device rather than changing security settings yourself.
Frequently Asked Questions
What is the difference between vbCrLf and vbNewLine?
Both insert a line break in a MsgBox on Windows. vbCrLf is a fixed carriage return plus line feed; vbNewLine is the platform's newline constant. For Excel dialogs, either works, and vbCrLf is the most common.
Can I use a line break in the MsgBox title?
No. The title is a single-line caption and breaks are not rendered there. Put the break in the prompt text instead.
Why does my MsgBox show the word vbCrLf?
Because it is inside the quotes. Move it outside: "text" & vbCrLf & "text".
Can I add more than two lines?
Yes. Repeat & vbCrLf & between each piece of text. Each repetition starts a new line.
Does this work in Excel for the web?
No. The VBA editor and MsgBox are part of the desktop Excel app; the browser version does not run VBA macros.
Can I format part of a MsgBox in bold?
No. A standard MsgBox supports plain text, an icon, buttons and a title only. For formatted text, use a UserForm with label controls.