Message Box Issues

tzw1378

Active Member
Joined
Jan 16, 2014
Messages
259
Hello,

I have no idea what's going on that's causing my message box script not to work. Here's the code:

Code:
Sub Message()
MsgBox("Here is your messaage",vbCritical,"Message")
End Sub

This results in a "Compile Error", "Expected: ="

Why is this? And how can I fix it?

Thank you in advance.
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,974
Office Version
  1. 365
Platform
  1. Windows
You usually only use parentheses when setting the Message Box equal to a variable.
So try it without them, i.e.:L
Code:
Sub Message()
    MsgBox "Here is your messaage", vbCritical, "Message"
End Sub
 

mohsin002

New Member
Joined
Jan 15, 2014
Messages
6
You need to create a variable which will store the MsgBox. Try this:

Code:
Sub Message()
Dim Answer as String
Answer = MsgBox("Here is your message",vbCritical,Title:="Message")
End Sub
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,974
Office Version
  1. 365
Platform
  1. Windows
You need to create a variable which will store the MsgBox.
You CAN, but you don't really NEED to. It all depends upon your needs and what you plan do it with it.
If you are just returning a value back to the screen, it is not necessary. If you want to save it for little, or add or modify it, then you probably would want to store it as a variable.
 

tzw1378

Active Member
Joined
Jan 16, 2014
Messages
259
You usually only use parentheses when setting the Message Box equal to a variable.
So try it without them, i.e.:L
Code:
Sub Message()
    MsgBox "Here is your message", vbCritical, "Message"
End Sub

No parens makes it work. Thank you for your help, all.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,477
Messages
5,601,893
Members
414,479
Latest member
Beau the dog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top