ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Confirm a choice before Macro (https://www.excelbanter.com/excel-discussion-misc-queries/205699-confirm-choice-before-macro.html)

JSnow

Confirm a choice before Macro
 
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

Dave Peterson

Confirm a choice before Macro
 
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

JSnow wrote:

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


--

Dave Peterson

Mike H

Confirm a choice before Macro
 
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

"JSnow" wrote:

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


JSnow

Confirm a choice before Macro
 
You guys are the best! If you're even in Ann Arbor...I owe you some beer.

"Dave Peterson" wrote:

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

JSnow wrote:

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


--

Dave Peterson



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

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