Popup Window with Yes (delete) / No (don't delete) function

slam

Well-known Member
Joined
Sep 16, 2002
Messages
831
Office Version
  1. 365
  2. 2019
I have a data validation drop down in B2 and when a user makes a selection, I want a popup window to appear if there is a value in any cell in the range K2:K41 (also a drop down validation list) which says "Would you like to clear the list?" with a Yes and No option.


If Yes is selected, it will delete the values in K2:K41.


If no is selected, the values are not deleted.


If there is no data in K2:K41, the popup window will not appear.


I would be eternally grateful if someone could assist with this :)

Thank you
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hello,

This code needs to go into the relevant sheet code window, not a standard module.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Address = "$B$2" Then
        If Range("K42").End(xlUp).Row > 1 Then
            MY_CHOICE = MsgBox("Would you like to clear the list?", vbYesNo, "Clear K2:K41")
            If MY_CHOICE = vbYes Then
                Range("K2:K41").ClearContents
            End If
        End If
    End If
    Application.EnableEvents = True
End Sub

Is it working as expected?
 
Upvote 0
Hello,

This code needs to go into the relevant sheet code window, not a standard module.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Address = "$B$2" Then
        If Range("K42").End(xlUp).Row > 1 Then
            MY_CHOICE = MsgBox("Would you like to clear the list?", vbYesNo, "Clear K2:K41")
            If MY_CHOICE = vbYes Then
                Range("K2:K41").ClearContents
            End If
        End If
    End If
    Application.EnableEvents = True
End Sub

Is it working as expected?

That is both so simple, and so genius :)

Works perfectly, thank you so much!
 
Upvote 0

Forum statistics

Threads
1,202,990
Messages
6,052,962
Members
444,622
Latest member
Kriszilla

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