Hi
i have a sheet called Ranges where i store 4 related columns of data on. on a second sheet called Summary I have 4 dependant comboboxes.
Combobox1 list values from column A on the Ranges sheet
the following code runs in the Worksheet_Activate event
i want to now populate combobox2 with unique values from the next related column
so i set the related range to go look in:
and here is where things start going weird:
comboboxes 3 and 4 are not pulling the unique values from the next columns through, instead it just repeats the values from the 2nd combobox.
Your assistance is appreciated.
i have a sheet called Ranges where i store 4 related columns of data on. on a second sheet called Summary I have 4 dependant comboboxes.
Combobox1 list values from column A on the Ranges sheet
the following code runs in the Worksheet_Activate event
Code:
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim rng As Range
Set ws1 = Sheets("Ranges")
Set ws2 = Sheets("Summary")
'lets first add the district values
For Each rng In ws1.Range("DISTRICT")
With Me.BxDistrict
.AddItem rng.Value
End With
Next rng
i want to now populate combobox2 with unique values from the next related column
so i set the related range to go look in:
Code:
With ws1
Set rng = .Range(.Range("I2"), .Range("I100").End(xlUp))
End With
and here is where things start going weird:
Code:
Dim CL as range
Dim ClAddress As String
Dim coll As New Collection
With Me.BxStn
.Clear
Set Cl = rng.Find(What:=Me.BxDistrict.Value, LookIn:=xlValues, LookAt:=xlWhole)
If Not Cl Is Nothing Then
ClAddress = Cl.Address
Do
On Error Resume Next
coll.Add Item:=Cl.Offset(0, 1).Value, Key:=CStr(Cl.Offset(0, 1).Value)
On Error GoTo 0
Set Cl = rng.FindNext(After:=Cl)
Loop While Not Cl Is Nothing And Cl.Address <> ClAddress
End If
For Each itm In coll
Me.BxStn.AddItem itm
Next itm
End With
Code:
'lets add the unique platoon names
With ws1
Set rng = .Range(.Range("J2"), .Range("J100").End(xlUp))
End With
With Me.BxPlt
.Clear
Set Cl = rng.Find(What:=Me.BxStn.Value, LookIn:=xlValues, LookAt:=xlWhole)
If Not Cl Is Nothing Then
ClAddress = Cl.Address
Do
On Error Resume Next
coll.Add Item:=Cl.Offset(0, 1).Value, Key:=CStr(Cl.Offset(0, 1).Value)
On Error GoTo 0
Set Cl = rng.FindNext(After:=Cl)
Loop While Not Cl Is Nothing And Cl.Address <> ClAddress
End If
For Each itm In coll
Me.BxPlt.AddItem itm
Next itm
End With
Code:
'lets add the unique staff names list
With ws1
Set rng = .Range(.Range("K2"), .Range("K100").End(xlUp))
End With
With Me.BxName
.Clear
Set Cl = rng.Find(What:=Me.BxPlt.Value, LookIn:=xlValues, LookAt:=xlWhole)
If Not Cl Is Nothing Then
ClAddress = Cl.Address
Do
On Error Resume Next
coll.Add Item:=Cl.Offset(0, 1).Value, Key:=CStr(Cl.Offset(0, 1).Value)
On Error GoTo 0
Set Cl = rng.FindNext(After:=Cl)
Loop While Not Cl Is Nothing And Cl.Address <> ClAddress
End If
For Each itm In coll
Me.BxName.AddItem itm
Next itm
End With
comboboxes 3 and 4 are not pulling the unique values from the next columns through, instead it just repeats the values from the 2nd combobox.
Your assistance is appreciated.