How do I create a warning message on a command button

L

lkreeder

I am a newbie to anything above basic level in Excel. I know how to create
and use Command Buttons, but I need to create a "Warning! Are You Sure"
message when you click the button, with "Yes", "No", and "Cancel" options.
 
J

JP

The code is

MsgBox "Warning! Are You Sure", vbYesNoCancel

But you'll want it to be part of a conditional statement, for example

If MsgBox("Warning! Are You Sure", vbYesNoCancel) = vbYes Then
Exit Sub
End If


HTH
 
R

Rick Rothstein

JP has given you an answer which should get you started. However, I have a
question... what is the difference between the user answering No and them
answering Cancel?
 
L

lkreeder

Thanks, JP. Worked like a charm. Maybe I need to buy one of those thick books
to learn this stuff.....
 
J

JP

Glad to hear it, but I think I actually typed it wrong, it should be

If MsgBox("Warning! Are You Sure", vbYesNo) = vbNo Then
Exit Sub
End If

because you want to exit if the user clicks "No". Also I agree with
Rick that No and Cancel basically mean the same thing, so Cancel is
unnecessary.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top