All,
I'm looking for some help... I've followed this tutorial: the third list
https://vbaf1.com/programming/cascading-dropdowns-useform/
ANd have expanded it to allow for 4 listboxes (from 3) - however the slight issue I'm having is that the third listbox is displaying duplicates and I'm not sure how to amend this to show only unique values applicable to the option selected in the second list box... Can anyone help explain how to expand the attached example above to do what I'm wanting (if it's possible)...
<code>
'1. Populate the Regions when you show the Form
Private Sub UserForm_Initialize()
lRow = 455 ' This is last row of your data sheet
For iCntr = 2 To lRow
If Range("A" & iCntr) <> Range("A" & iCntr - 1) Then 'To avoid duplication
lstRegion.AddItem Range("A" & iCntr)
End If
Next
End Sub
'2. Populate the Countries when you change a Regions
Private Sub lstRegion_Change()
lRow = 455 ' This is last row of your data sheet
lstCountry.Clear
lstProducts.Clear
For iCntr = 2 To lRow
If Range("A" & iCntr) = lstRegion.Value And Range("B" & iCntr) <> Range("B" & iCntr - 1) Then
lstCountry.AddItem Range("B" & iCntr)
End If
Next
End Sub
'3. Populate the Products when you change the country
Private Sub lstCountry_Change()
lRow = 455 ' This is last row of your data sheet
lstProducts.Clear
For iCntr = 2 To lRow
If Range("A" & iCntr) = lstRegion.Value And Range("B" & iCntr) = lstCountry.Value Then
lstProducts.AddItem Range("C" & iCntr)
End If
Next
End Sub
'4. Populate the Products when you change the country
Private Sub lstProducts_Change()
lRow = 455 ' This is last row of your data sheet
lstRegulated.Clear
For iCntr = 2 To lRow
If Range("A" & iCntr) = lstRegion.Value And Range("C" & iCntr) = lstProducts.Value Then
lstRegulated.AddItem Range("D" & iCntr)
End If
Next
End Sub
'5. Exit Button
Private Sub CommandButton1_Click()
Unload Me
End Sub
</code>
I'm looking for some help... I've followed this tutorial: the third list
https://vbaf1.com/programming/cascading-dropdowns-useform/
ANd have expanded it to allow for 4 listboxes (from 3) - however the slight issue I'm having is that the third listbox is displaying duplicates and I'm not sure how to amend this to show only unique values applicable to the option selected in the second list box... Can anyone help explain how to expand the attached example above to do what I'm wanting (if it's possible)...
<code>
'1. Populate the Regions when you show the Form
Private Sub UserForm_Initialize()
lRow = 455 ' This is last row of your data sheet
For iCntr = 2 To lRow
If Range("A" & iCntr) <> Range("A" & iCntr - 1) Then 'To avoid duplication
lstRegion.AddItem Range("A" & iCntr)
End If
Next
End Sub
'2. Populate the Countries when you change a Regions
Private Sub lstRegion_Change()
lRow = 455 ' This is last row of your data sheet
lstCountry.Clear
lstProducts.Clear
For iCntr = 2 To lRow
If Range("A" & iCntr) = lstRegion.Value And Range("B" & iCntr) <> Range("B" & iCntr - 1) Then
lstCountry.AddItem Range("B" & iCntr)
End If
Next
End Sub
'3. Populate the Products when you change the country
Private Sub lstCountry_Change()
lRow = 455 ' This is last row of your data sheet
lstProducts.Clear
For iCntr = 2 To lRow
If Range("A" & iCntr) = lstRegion.Value And Range("B" & iCntr) = lstCountry.Value Then
lstProducts.AddItem Range("C" & iCntr)
End If
Next
End Sub
'4. Populate the Products when you change the country
Private Sub lstProducts_Change()
lRow = 455 ' This is last row of your data sheet
lstRegulated.Clear
For iCntr = 2 To lRow
If Range("A" & iCntr) = lstRegion.Value And Range("C" & iCntr) = lstProducts.Value Then
lstRegulated.AddItem Range("D" & iCntr)
End If
Next
End Sub
'5. Exit Button
Private Sub CommandButton1_Click()
Unload Me
End Sub
</code>
Last edited: