add filtered items to combobox

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
I'm aware of how to add items to a combobox with a specific range; but am not sure how this works with auto filtered items.

Code:
With iTe
    Selection.AutoFilter Field:=8, Criteria1:="=*" & ComboBox1.Text & "*", Operator:=xlAnd '8 may need to be adjusted
    ActiveWindow.SmallScroll Down:=-18
End With

I use the above to retrieve results but would like to add each line of result into a combobox so the user can select from it accordingly.
A second part to this is to make the "field:=8" into a variable. I have the column letter available but am not sure how I can turn it into a number (easily) and then use it in this above code as a var.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe something like this... Let's assume that you'd like to add filtered items from the second column of your selection to your combo box, try...

Code:
[font=Verdana]    [color=darkblue]Dim[/color] VisibleRng [color=darkblue]As[/color] Range
    [color=darkblue]Dim[/color] Cell [color=darkblue]As[/color] Range
    
    [color=darkblue]With[/color] Selection
        .AutoFilter Field:=8, Criteria1:="=*" & ComboBox1.Text & "*"
        [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]Resume[/color] [color=darkblue]Next[/color]
        [color=darkblue]Set[/color] VisibleRng = .Columns(2).Offset(1, 0).Resize(.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible)
        [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]GoTo[/color] 0
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    
    [color=darkblue]If[/color] [color=darkblue]Not[/color] VisibleRng [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
        [color=darkblue]With[/color] ComboBox2
            .Clear
            [color=darkblue]For[/color] [color=darkblue]Each[/color] Cell [color=darkblue]In[/color] VisibleRng
                .AddItem Cell
            [color=darkblue]Next[/color] Cell
        [color=darkblue]End[/color] [color=darkblue]With[/color]
    [color=darkblue]Else[/color]
        MsgBox "No records found...", vbExclamation
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    [/font]

Change the desired column and name of the combo box, accordingly.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,758
Members
452,940
Latest member
rootytrip

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