• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VB MsgBox for a macro?

TSDible

Golden Member
Hey guys... I'm not really a VB programmer, but I need some help.

Basically, I recorded a macro that deletes a bunch of data in my Excel spreadsheet. I assigned the macro to a button.

I want to have a MsgBox pop up when a user clicks on the button to ask them if they are sure that they want to clear the data. If they click ok, it will continue the deletion. If they click cancel, the macro will end and the data will not be deleted. Cancel should be the default option.

I've tried adding it, but I don't really know the syntax. Here is what I have so far...

Sub Data_Clear()
'
' Data_Clear Macro
' Macro recorded 5/5/2003 by diblesd
'

'
Range("U42:U61&quot😉.Select
Application.CutCopyMode = False
Selection.Copy
Range("C42&quot😉.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Data Import&quot😉.Select
Range("A2:N26&quot😉.Select
Application.CutCopyMode = False
Selection.ClearContents
Range("A28:N53&quot😉.Select
Selection.ClearContents
Range("B55:H200&quot😉.Select
Selection.ClearContents
Range("K55:Q200&quot😉.Select
Selection.ClearContents
Range("A2&quot😉.Select
Sheets("Cal Import&quot😉.Select
Range("A2:N20&quot😉.Select
Selection.ClearContents
Range("A22:N45&quot😉.Select
Selection.ClearContents
Range("Q2:Q21&quot😉.Select
Selection.ClearContents
Range("A2&quot😉.Select
Sheets("Data Entry&quot😉.Select
Range("A2:G2&quot😉.Select
End Sub

Thanks in advance for any help.
 
Sub Data_Clear()
'
response = MsgBox("Are you sure you want to delete?", vbOKCancel + vbDefaultButton2, "Confirm Delete&quot😉
If response = vbOK Then
Range("U42:U61&quot😉.Select
Application.CutCopyMode = False
Selection.Copy
Range("C42&quot😉.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Data Import&quot😉.Select
Range("A2:N26&quot😉.Select
Application.CutCopyMode = False
Selection.ClearContents
Range("A28:N53&quot😉.Select
Selection.ClearContents
Range("B55:H200&quot😉.Select
Selection.ClearContents
Range("K55:Q200&quot😉.Select
Selection.ClearContents
Range("A2&quot😉.Select
Sheets("Cal Import&quot😉.Select
Range("A2:N20&quot😉.Select
Selection.ClearContents
Range("A22:N45&quot😉.Select
Selection.ClearContents
Range("Q2:Q21&quot😉.Select
Selection.ClearContents
Range("A2&quot😉.Select
Sheets("Data Entry&quot😉.Select
Range("A2:G2&quot😉.Select
End If

End Sub
 
Back
Top