I want fill a drop down list based on user selection in another. I'm trying to update the contents of a field based on selection in another by adding the items on the fly once the first combobox (cbo_park) is selected.
I have a four drop down lists:
The first drop down cbo_park has the following options:
Central
East
West
I have a second workbook called lookupRoom which contains the following table:
roomCode park
A.0.01 Central
A.2.01 Central
A.3.01 Central
HE.0.10 East
HE.0.21 East
HE.0.22 East
KG.1.07 West
KG.1.09 West
KG.1.10 West
When the user selects the Central park option under the first drop down cbo_park I only want rooms in the Central park to be displayed in dropdown cbo_prefRoom1, cbo_prefRoom2 and cbo_prefRoom3. How would I go about achieving this?
Please find below my attempts so far. I keep receiving an error at the line: Me.cbo_prefRoom1.RemoveItem 0
.
Private Sub cbo_park_Change()
Dim lLoop As Long, rgLoop As Range
For lLoop = 1 To Me.cbo_park.ListCount
Me.cbo_prefRoom1.RemoveItem 0
Next lLoop
Sheets("lookupRoom").[a1].CurrentRegion.AutoFilter
Sheets("lookupRoom").[a1].CurrentRegion.AutoFilter Field:=3, Criteria1:=Left(Me.cbo_park.Value, 2)
For Each rgLoop In Sheets("lookupRoom").[a1].CurrentRegion.Offset(1).SpecialCells(xlCellTypeVisible).Columns(1).Cells
If Len(rgLoop) > 0 Then
Me.cbo_prefRoom1.AddItem rgLoop
End If
Next rgLoop
End Sub