VBA code to reset drop down list

Phx007

New Member
Joined
Apr 9, 2020
Messages
4
Office Version
  1. 2016
  2. 2013
  3. 2011
Platform
  1. Windows
Hello. I am in need of some help here.

I have 2 drop down lists on my spreadsheet.

what I need is so when I select an entry in drop down list #1 for the other drop down list #2 to clear. Vice Versa I also need the same code to clear drop down list #1 when drop down list #2 options is selected. Thank you!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to the MrExcel board!

when I select an entry in drop down list #1 for the other drop down list #2 to clear.
Do you really mean for the other list to clear or do you mean to clear the other cell that has the other drop-down list as its Data Validation list.
 
Upvote 0
Hello , sorry I might have typed my question in a hurry. So what I mean is that I want list #1 to clear any validation that is currently selected when any validation is selected from list #2. So I basically want the two lists to cancel each other out when one of the other is selected.

If any drop down validation is selected from list #1 then list #2 clears AND If any drop down validation is selected from list #2, list #1 clears. Hopefully that made sense thank you so much!
 
Upvote 0
I have tried to use this code but it freezes my excel. It works perfectly if I just have one target address but then only one drop down list resets and I am left with the second one that I have to manually clear


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$G$4" Then

Range("G6").Value = "Please Select..."

End If

If Target.Address = "$G$6" Then

Range("G4").Value = "Please Select..."

End If

End Sub
 
Upvote 0
but it freezes my excel.
That is because when you change one of the cells, your code changes the other one which triggers this worksheet change code which will clear the first cell again which triggers this worksheet change code which will clear the second cell again which triggers this worksheet change code ...

You just need to add a few lines to stop that re-triggering.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

  If Target.Address = "$G$4" Then
    Application.EnableEvents = False
    Range("G6").Value = "Please Select..."
    Application.EnableEvents = True
  End If
  
  If Target.Address = "$G$6" Then
    Application.EnableEvents = False
    Range("G4").Value = "Please Select..."
    Application.EnableEvents = True
  End If

End Sub
 
Upvote 0
Just another way:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("G4, G6")) Is Nothing Then
    Application.EnableEvents = False
    Range(IIf(Target.Address(0, 0) = "G4", "G6", "G4")).Value = "Please Select..."
    Application.EnableEvents = True
  End If
End Sub
 
Upvote 0
Thank you all! both worked like a charm. I really appreciate it!
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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