Dependent Dropdown Lists

jues

New Member
Joined
Mar 17, 2023
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Dear friends

I use google translator because my english is not very good, specifically my problem is that for a small project in my university I have created three dependent drop-down lists: States, Municipalities, Parishes when using the line of code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("D13").Address Then
Range("G13").Value = ""
End If

It works perfectly since when changing the value of the cell States ("D13") it places the Municipalities cell ("G13") blank, however when repeating the same line of code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("G13").Address Then
Range("I13").Value = ""
End If
End Sub

So that when changing the cell of Municipalities ("G13") leaves the cell of Parishes ("I13") blank, the system begins to indicate an alert that says:

Compilation Error
Ambiguous name detected Worksheet_Change

Could you guide me how to solve this error and what would be the correct lines of code that I should place?
I will be very grateful to you for any help you can give me with this little problem.
 

Attachments

  • Imagen1.jpg
    Imagen1.jpg
    129.6 KB · Views: 6
  • Imagen2.jpg
    Imagen2.jpg
    170.5 KB · Views: 6
  • Imagen3.jpg
    Imagen3.jpg
    132.4 KB · Views: 5
  • Imagen4.jpg
    Imagen4.jpg
    184.5 KB · Views: 4

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi,
In a given sheet module, you can only have one single event of a specific type (such as Worksheet_Change)
So you do need to combine both codes into one ...
You could test following
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("D13", "G13")) Is Nothing Then Exit Sub
    Select Case Target.Column
        Case 4
            Target.Offset(0, 3).ClearContents
        Case 7
            Target.Offset(0, 2).ClearContents
    End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,873
Messages
6,127,464
Members
449,384
Latest member
purevega

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