***This is cross-posted on StackOverflow at this link . It has received no comments yet, so I'm posting here as well***
I have a User Form where a user makes a selection in a list box (called Relay). That selection populates an option in a second list box (Called Squad) based upon the following criteria:
I have a User Form where a user makes a selection in a list box (called Relay). That selection populates an option in a second list box (Called Squad) based upon the following criteria:
- The value in column "O" is not blank
- The value in column "D" IS blank
- The value in column "L" matches the user's selection in the 1st list box (Relay)
VBA Code:
Private Sub lstRelayNumber_Click()
Dim Dict As Object
Dim LastRow As Long
Dim Relay As Range, vL, vD, vO
Dim RelayNumber As Long
Set Dict = CreateObject("Scripting.Dictionary")
With Sheets("Score Sheet")
LastRow = .Cells(.Rows.Count, "O").End(xlUp).Row
Me.lstSquadNumber.Clear
RelayNumber = Me.lstRelayNumber.Value
For Each Relay In .Range("O2:O" & LastRow).Cells
vO = Relay.Value 'Column O value
vD = .Range("D" & Relay.Row).Value 'Column D value
vL = .Range("L" & Relay.Row).Value 'Column L Value
If Len(vL) = RelayNumber And Len(vD) = 0 And Len(vO) > 0 Then
If Not Dict.exists(vO) Then
Dict.Add vO, 1
lstSquadNumber.AddItem vO
End If
End If
Next Relay
End With
End Sub