ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need Warning Box before deleting cells (https://www.excelbanter.com/excel-programming/373421-need-warning-box-before-deleting-cells.html)

dzierzekr

Need Warning Box before deleting cells
 
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
--
dzierzekr

Die_Another_Day

Need Warning Box before deleting cells
 
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

dzierzekr wrote:
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
--
dzierzekr



Andrew Taylor

Need Warning Box before deleting cells
 
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


Die_Another_Day wrote:
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

dzierzekr wrote:
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
--
dzierzekr




All times are GMT +1. The time now is 02:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com