ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Populate Combo Box With Filtered List (https://www.excelbanter.com/excel-programming/273780-re-populate-combo-box-filtered-list.html)

Kinne

Populate Combo Box With Filtered List
 
Thank you Tom !
This works fine to add the filtered items to the a single column combo
box. But I need to fill the cbo with 3 columns (ID, foreign ID,
value). The ID (first column) will be used to filter the next cbo, but
I need to display a "human understandable" value in the cbo. I thought
about using "cbo.list" ... but I'm stuck. More help for me ??

Kinne


Dim rng As Range
For Each rng In Worksheets(WorksheetFiltered).Range(RangeFiltered) .Rows
If rng.EntireRow.Hidden = False Then
' magic code here
End If
Next rng
<<

Kinne


Tom Ogilvy

Populate Combo Box With Filtered List
 
Private Sub UserForm_Initialize()
Dim rng As Range
cbo2.RowSource = ""
cbo2.Clear
cbo2.ColumnCount = 3
For Each rng In Range("Database").Rows
If rng.EntireRow.Hidden = False Then
cbo2.AddItem rng.Cells(1, 1).Value
cbo2.List(cbo2.ListCount - 1, 1) = rng.Cells(1, 2)
cbo2.List(cbo2.ListCount - 1, 2) = rng.Cells(1, 3)
End If
Next rng
End Sub

as an example.

--
Regards,
Tom Ogilvy




"Kinne" wrote in message
om...
Thank you Tom !
This works fine to add the filtered items to the a single column combo
box. But I need to fill the cbo with 3 columns (ID, foreign ID,
value). The ID (first column) will be used to filter the next cbo, but
I need to display a "human understandable" value in the cbo. I thought
about using "cbo.list" ... but I'm stuck. More help for me ??

Kinne


Dim rng As Range
For Each rng In

Worksheets(WorksheetFiltered).Range(RangeFiltered) .Rows
If rng.EntireRow.Hidden = False Then
' magic code here
End If
Next rng
<<

Kinne




Kinne

Populate Combo Box With Filtered List
 
Tom,

Yes, that's it, thank you very much Tom !

Kinne


Private Sub UserForm_Initialize()
Dim rng As Range
cbo2.RowSource = ""
cbo2.Clear
cbo2.ColumnCount = 3
For Each rng In Range("Database").Rows
If rng.EntireRow.Hidden = False Then
cbo2.AddItem rng.Cells(1, 1).Value
cbo2.List(cbo2.ListCount - 1, 1) = rng.Cells(1, 2)
cbo2.List(cbo2.ListCount - 1, 2) = rng.Cells(1, 3)
End If
Next rng
End Sub



All times are GMT +1. The time now is 12:38 PM.

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