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

  • Thread starter Thread starter mike_vr
  • Start date Start date
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
 
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
 
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
 

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

Back
Top