"Are You Sure?" Prompt on "Clear All" Button Press

Disarmonious

Board Regular
Joined
Oct 31, 2016
Messages
139
Hello,

I would like Excel to prompt the user with this question, "Are You Sure" when selecting the 'Clear All' button on my form. Here's what my code looks like now:

Macros Name =
ClearYNH

Sub ClearYNH()
'
' ClearYNH Macro
'
'
Range("BW9:BW20,BV9:BV20,BU9:BU20,BT9:BT20,BS9:BS20,BR9:BR20").Select
Range("BR9").Activate
Selection.ClearContents
Range("BR9").Select


End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
Sub ClearYNH()
Dim answer As Variant


  answer = MsgBox("Are you sure ?", vbYesNo + vbQuestion, "Really ?")
  
    If answer = vbYes Then
        Range("BW9:BW20,BV9:BV20,BU9:BU20,BT9:BT20,BS9:BS20,BR9:BR20").Select
        Range("BR9").Activate
        Selection.ClearContents
        Range("BR9").Select


    Else
        Exit Sub
    End If


End Sub
 
Upvote 0
Code:
Sub ClearYNH()
  If MsgBox("Are you SURE?", vbYesNo) = vbYes Then Range("BR2:BR9, BS9:BW20").ClearContents
End Sub
 
Upvote 0
Try
Code:
Sub ClearYNH()
'
' ClearYNH Macro
'
If MsgBox("Are you sure you want to clear the form?", vbYesNo) = vbNo Then Exit Sub
Range("BW9:BW20,BV9:BV20,BU9:BU20,BT9:BT20,BS9:BS20,BR9:BR20").ClearContents
Range("BR9").Select


End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top