Populate a combobox

  • Thread starter Thread starter Rory
  • Start date Start date
R

Rory

I currently have combobox1 that looks to a hidden sheet
and uses the first column (name) to populate (removing
duplicate occurences of the name). What I need to do now
is populate combobox2 based on the combobox1, that pulls
data from the second column of the hidden sheet, but only
those where column 1 equals combobox 1.
 
Why not fill them at the same time.

Combobox1.AddItem Cells(rw,1)
Combobox2.AddItem cells(rw,2)
 
Here's the code as it stands, the range "client" being the
first column of names, tried as you suggested but I think
that beacause the original range is only the first column
this wouldn't work, also when it screens out duplicates
all will be unique due to the second column??:

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




Set AllCells = Worksheets("Client").Range("client")

Worksheets("sheet1").Select

ComboBox5.Clear
ComboBox4.Clear


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

ComboBox5.AddItem item

Next item
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top