How to Add a New Line to a Message Box (MsgBox) in Excel VBA Macros

Add to Favorites
Author: | Edits: WillieD24, don

I'll show you how to create a message box popup window in Excel that contains text on multiple lines. This allows you to do the same thing as hitting the "enter" key when writing a message to go to a new line.

The most basic MsgBox code in Excel vba is like this:

Sub test()
MsgBox "Hi! This is a message box"
End Sub

This outputs a simple popup message box window when run.

vbNewLine Method

This macro adds a new line in the message box:

Sub test2()
MsgBox "Hi!" & vbNewLine & "This is a message box"
End Sub

Note the vbNewLine that was added.  This is what actually adds the new line to the code.  Also, note that you have to use double quotes and an ampersand (&) before you can input the vbNewLine text and then you need to do the same thing again in order to input the rest of the message.

Adding as many lines as needed is really easy.  Here is another sample with two new lines, which makes a new blank line appear between the two parts of the message.

Sub test3()
MsgBox "Hi!" & vbNewLine & vbNewLine & "This is a message box"
End Sub

vbCrLf Method

Sub test4()
MsgBox "Hi!" & vbCrLf & vbCrLf &  "This is a message box"
End Sub   

where CrLf stands for: carriage return line feed.

Add Another Line within the Macro Itself

If your message is a bit wordy, add an underscore ( _ )and you can continue the message on a new line in the code window to reduce the amount of horizonal scrolling to see the complete text of the message.

Sub test5()
MsgBox "Hi!" & vbCrLf & vbCrLf & _
       "This is a message box"
End Sub   


Choose whichever method you prefer and stick with it - the differences with them are technical and almost never matter, especially with simple message box pop-up windows.

Question? Ask it in our Excel Forum

Our Excel Courses

  • Skill Level: All Levels
  • |
  • 5 hours+

How to make a fully featured professional form in Excel that is unbreakable. This includes how to use the form to store, view, edit, and delete data from a data storage worksheet.

  • Skill Level: All Levels
  • |
  • 2 hours

Send Emails from Excel using VBA and Macros. This course starts from the Basics and builds up to more advanced examples with attaching workbooks, worksheets, PDF's, automatically sending emails, including a signature, error handling, increasing speed, and more.

Similar Content on TeachExcel
Macro to add a New Line to Message Box Pop-up Windows in Excel
Macro: This is a very simple Message Box, pop-up window, macro for Excel that illustrates how to ...
How to Create and Manage a Chart in Excel
Tutorial: In this tutorial I am going to introduce you to creating and managing charts in Excel. Bef...
How to Add Boxes, Buttons, Arrows, Speech-Bubbles, Hearts, and More to a Spreadsheet in Excel
Tutorial: In this tutorial I am going to cover inserting and editing Shapes in an Excel workbook, as...
Excel Macro to Save a Specific Worksheet as a New File
Macro: This Excel Macro allows you to save a specific worksheet within the Excel Workbook to its ...
How to Add Formatting to Cells and Data in Excel Styles, Fonts, Colors, & More
Tutorial: In this tutorial I will cover how to use the various formatting tools in Excel. The Format...
Run a Macro When a Specific Cell Changes in Excel
Tutorial: Run a macro in Excel when a specific cell is changed; this also covers when a cell within...