combo box.

dcmb

Board Regular
Joined
Feb 3, 2009
Messages
116
I googled but couldn't find an answer.

I'm still pretty new to VBA. And I want to use a combo box / list box to show the items in a column which I can select.

For example:

HTML:
         A
1     apple
2     orange
3     apple
4     banana

I want the combo box / list box to show the list of items in column A. And say, I select orange on the combo box / list box then I want to use the selected data for filtering.

All suggestions and ideas are welcomed.

Thanks in advance.
 
Try
Code:
Dim cbblist As String, lr As Long
lr = Cells(Rows.Count, "I").End(xlUp).Row
cbblist = Sheets("sheet2").Range("I1:I" & lr)
Sheets("sheet1").cbb1.ListFillRange = "=cbblist"

The code has no errors. But after running them, the combo box is still empty and doesn't show the items under column I.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
IS the ComboBox actually named cbb1 ?
 
Upvote 0
This code works for me !
Chack the combo box properties and make sure the name is changed there as well.
Code:
Sub MM()
Dim cbblist As Range, lr As Long
lr = Cells(Rows.Count, "I").End(xlUp).Row
Set cbblist = Sheets("sheet2").Range("I1:I" & lr)
Sheets("sheet1").cbb1.ListFillRange = "=cbblist"
End Sub
 
Upvote 0
Everything is correct. And the codes run fine and successfully. But my combo box is till empty after running the codes.

I'm using ActiveX control for the combo box. Is that ok? Or should I use Form control?
 
Upvote 0
Create a named range for the data in sheet2 as cbblist
and rerun the code
 
Upvote 0
Create a named range for the data in sheet2 as cbblist
and rerun the code

works now. Thank you.

Would like to understand the code. May I know what does "lr = Cells(Rows.Count, "I").End(xlUp).Row" do? Are you asking VBA to count the no. of rows in column I?

Thanks in advance.
 
Upvote 0
Yes, it counts the cells that have something in them from the bottom of the sheet up to that last used row, and down from row 1
 
Upvote 0
See both methods of doing it
Code:
Private Sub fillit() 'list by cell method
Dim cell As Range, lr As Long
lr = Sheets("Sheet2").Cells(Rows.Count, "I").End(xlUp).Row
With Worksheets("Sheet1").OLEObjects("cbb1").Object
    .Clear
        For Each cell In Sheets("Sheet2").Range("I1:I" & lr)
            .AddItem cell.Value
        Next cell
End With
End Sub

OR


Private Sub MM() 'named range method
Dim cbblist As Range
Sheets("sheet1").cbb1.ListFillRange = "=cbblist"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,572
Members
449,237
Latest member
Chase S

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top