Subscribe for Weekly Tutorials
BONUS: subscribe now to download our Top Tutorials Ebook!
How to Add a New Line to a Message Box (MsgBox) in Excel VBA Macros
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.
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
Hope this helps! :)
Question? Ask it in our Excel Forum
Macro: This is a very simple Message Box, pop-up window, macro for Excel that illustrates how to ...
Tutorial: In this tutorial I am going to introduce you to creating and managing charts in Excel. Bef...
Tutorial: In this tutorial I am going to cover inserting and editing Shapes in an Excel workbook, as...
Macro: This Excel Macro allows you to save a specific worksheet within the Excel Workbook to its ...
Tutorial: In this tutorial I will cover how to use the various formatting tools in Excel. The Format...
Tutorial: Run a macro in Excel when a specific cell is changed; this also covers when a cell within...