Hey everyone,
I'm currently learning to do VBA (still in the very beginner stage) and I am trying to to write some code regarding three dependent data validation lists. Let's call them "Country", "State", and "City".
I want the "City" list to reset when I change the "State" list. Similarly, I want the "City" and "State" lists to reset when I change the "Country" list.
I found some VBA code that enables me to reset one of the lists when I change another, but I haven't been able to extend the code to do exactly what I want.
I appreciate your help and I hope to learn from it!
P.S. Here is the code I found. Say "E32" is "State" and "G32" is "City".
Option Explicit
Public Prior As String
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Intersect(Target, Range("E32")) Is Nothing Then
If Target <> "" And Target <> Prior Then Range("G32").ClearContents
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("E32")) Is Nothing Then _
Prior = Target.Text
End Sub
I'm currently learning to do VBA (still in the very beginner stage) and I am trying to to write some code regarding three dependent data validation lists. Let's call them "Country", "State", and "City".
I want the "City" list to reset when I change the "State" list. Similarly, I want the "City" and "State" lists to reset when I change the "Country" list.
I found some VBA code that enables me to reset one of the lists when I change another, but I haven't been able to extend the code to do exactly what I want.
I appreciate your help and I hope to learn from it!
P.S. Here is the code I found. Say "E32" is "State" and "G32" is "City".
Option Explicit
Public Prior As String
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Intersect(Target, Range("E32")) Is Nothing Then
If Target <> "" And Target <> Prior Then Range("G32").ClearContents
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("E32")) Is Nothing Then _
Prior = Target.Text
End Sub