MsgBox in Excel VBA

The MsgBox function displays a message to the user. Place a command button and enter the following code:

1. A simple message.

MsgBox "This is fun"

Result after clicking the command button:

MsgBox in Excel VBA

2. A little more advanced message. First, enter a number (12) into cell A1.

MsgBox "Entered value is " & Range("A1").Value

Result after clicking the command button:

Note: You can use ‘&’ to join two strings. Even though Range(“A1”).Value is not a string, it still works in this situation.

3. To break your message into two lines, simply use vbNewLine.

MsgBox "FLine 1" & vbNewLine & " Line 2"

Result after clicking the command button:

1/3 Completed! Learn much more about msgboxes ➝
Next Chapter: Workbook and Worksheet Object