ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Populate a combobox (https://www.excelbanter.com/excel-programming/300898-populate-combobox.html)

Rory[_3_]

Populate a combobox
 
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.

Tom Ogilvy

Populate a combobox
 
Why not fill them at the same time.

Combobox1.AddItem Cells(rw,1)
Combobox2.AddItem cells(rw,2)

--
Regards,
Tom Ogilvy

"Rory" wrote in message
...
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.




Rory[_3_]

Populate a combobox
 
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, befo=j
NoDupes.Add Swap2, befo=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
-----Original Message-----
Why not fill them at the same time.

Combobox1.AddItem Cells(rw,1)
Combobox2.AddItem cells(rw,2)

--
Regards,
Tom Ogilvy

"Rory" wrote in message
...
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.



.



All times are GMT +1. The time now is 08:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com