Dependent Dropdown Lists

jues

New Member
Joined
Mar 17, 2023
Messages
15
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: 7
  • Imagen2.jpg
    Imagen2.jpg
    170.5 KB · Views: 7
  • Imagen3.jpg
    Imagen3.jpg
    132.4 KB · Views: 6
  • Imagen4.jpg
    Imagen4.jpg
    184.5 KB · Views: 5

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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