Confirm a choice before Macro

J

JSnow

I have a macro attached to a button that will clear all data on a page. I'd
like there to be a confirmation (that's how I know it from javascript) to
preceed the macro. Here's the code thus far:

Sub clearAll()
Range("D3,...M48").ClearContents
End Sub

Is there something I can throw in the macro, before the Range line that will
ask, "Are you sure you want to delete all data?" If yes then fire macro, if
no then end.

Thanks, JSnow
 
D

Dave Peterson

Option Explicit
Sub clearAll()
Dim Resp as long

resp = msgbox(Prompt:="Are you sure???",buttons:=vbyesno)
if resp = vbyes then
activesheet.Range("D3,...M48").ClearContents
end if
End Sub
 
M

Mike H

try this,

Sub clearAll()
response = MsgBox("Are you sure you want to delete all data?", vbOKCancel)
If response = vbCancel Then Exit Sub
Range("D3:M48").ClearContents
End Sub

Mike
 
Top