MsgBox
The Excel VBA MsgBox (message box) is a dialog box you can use in Excel VBA to display information to the users of your program. Below you can find three easy examples on how to create a MsgBox in Excel VBA.
1. To show a MsgBox with the message "This is fun", place a command button on your worksheet and simply add the following code line:
Result when you click the command button on the sheet:

2. Now we try to create a little more advanced MsgBox.
Enter a random number into cell A1.
Instead of "This is Fun", add the following code line:
Result when you click the command button on the sheet:

We used the & operator to concatenate (join) two strings. Although Range("A1").value is not a string, it works here.
3. To start a new line in a message box, you can use vbNewLine. Add the following code line:
Result when you click the command button on the sheet:

Did you find this information helpful? Show your appreciation, vote for us.
Go to Top: MsgBox | Go to Next Topic: Macro Errors