S
sven_dau
I have a combobox that reflects a list (in a different tab) withou
duplications.
At the moment it is selecting names in columnC. Additionally, I want t
show only those names that meet a criteria in columnA. The selectio
criteria is entered in cell M1 of the base sheet.
Here's my code I use so far.
Private Sub worksheet_Activate()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item
Dim rng As Range
Me.combobox1.Clear
Set AllCells = Worksheets("NKADaten").Range("C4:C200")
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) > NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, before:=j
NoDupes.Add Swap2, before:=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i
For Each Item In NoDupes
Me.combobox1.AddItem Item
Next Item
End Sub
Many thanks for your help.
Sve
duplications.
At the moment it is selecting names in columnC. Additionally, I want t
show only those names that meet a criteria in columnA. The selectio
criteria is entered in cell M1 of the base sheet.
Here's my code I use so far.
Private Sub worksheet_Activate()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item
Dim rng As Range
Me.combobox1.Clear
Set AllCells = Worksheets("NKADaten").Range("C4:C200")
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) > NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, before:=j
NoDupes.Add Swap2, before:=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i
For Each Item In NoDupes
Me.combobox1.AddItem Item
Next Item
End Sub
Many thanks for your help.
Sve