Simple Yes / No messagebox followed by an if then else formula

M

mike_vr

Hi there

Created a macro that clears a spreadsheet, and have put in a button that
runs it once clicked. Now all I want is a simple yes/no/cancel option to come
up that, once the button is clicked, the user can still cancel before the
macro runs, unless he is happy to go with it in which case all the data will
be cleared.
Pretty simple I'm sure, but I have no idea how to launch the messagebox, and
then based on the yes / no click to run the macro or not?!?

Any thoughts?

Thanks,
mike
 
J

Jim Rech

If MsgBox("Proceed?", vbYesNo, "Clear sheet") = vbYes Then
'Clear code
End If


--
Jim
| Hi there
|
| Created a macro that clears a spreadsheet, and have put in a button that
| runs it once clicked. Now all I want is a simple yes/no/cancel option to
come
| up that, once the button is clicked, the user can still cancel before the
| macro runs, unless he is happy to go with it in which case all the data
will
| be cleared.
| Pretty simple I'm sure, but I have no idea how to launch the messagebox,
and
| then based on the yes / no click to run the macro or not?!?
|
| Any thoughts?
|
| Thanks,
| mike
 
S

Steve Yandl

Here is an option that will give you the options 'ok' and 'cancel'. Take a
look at help for Msgbox if you need yes/no or yes/no/cancel.

x = MsgBox("Do you want to run me", vbOKCancel, _
"Approval Option")
If x = 2 Then
Exit Sub
Else
' your code to run goes here
End If


Steve Yandl
 
Top