Put the variable after MsgBox: MsgBox total shows its value. To add a label, join text and the variable with &: MsgBox "Total sales: " & total.
Use vbNewLine to put values on separate lines, and the third argument for a title:
<pre>MsgBox "Region: " & region & vbNewLine & _</pre>
"Sales: " & Format(total, "$#,##0.00"), vbInformation, "Summary"
Format numbers and dates before showing them. MsgBox shows the raw value, such as 1234.5 instead of $1,234.50, and dates in the PC’s regional format. Use Format(total, "#,##0.00") or Format(Date, "dd mmm yyyy").
Join with &, not +: "Total: " + total stops with a type mismatch when total is a number. If the box comes up empty, the variable name is probably misspelt; Option Explicit at the top of the module catches that before the code runs.
You can also use a variable in a message box. Let’s say you have a variable that stores a specific value in that variable.
Now you can use that variable in the message box to show the value to the user. In the following example, we have used a macro where we have used the for loop and we have a function to generate a random number.

When you run this code, it loops 10 times and then generates a random number and stores that number in the variable. In the next line of code, we used the same variable to show the value in the message box.

Sub generateRandomNumber()
Dim i As Integer, rNumber As Integer
i = 10
For i = 1 To i
rNumber = WorksheetFunction.RandBetween(1000, 2000)
MsgBox rNumber
Next i
End Sub
Related Tutorials
Written by
Puneet Gogia
Microsoft MVP — Excel · Founder, Excel Champs
Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.