Need Warning Box before deleting cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey
Thanks to all for the HELP I'm getting from this group!
I have a macro set to clear all the cells in a work schedule
spreadsheet and a button to run the macro.
When I push the button I need a WARNING BOX to appear
to ask something like "Are you sure you want to clear the spreadsheet?"
So as to not accidently clear the worksheet.
How do I do this. Additional code written into the macro?
thanks
Raymond
 
Sub YourSub()
If MsgBox("Are you sure you want to clear the spreadsheet?", vbYesNo +
vbCritical) = vbNo Then Exit Sub
'YourCode
End Sub

HTH

Charles Chickering
 
As a matter of style, I would use vbQuestion (or possibly
vbExclamation) rather than vbCritical

You can also try to avoid accidents by making
the No button the default:

If MsgBox("Are you sure you want to clear the spreadsheet?", _
vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then Exit Sub
 

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