Filter a ComboBox Using Change Event

tlafferty

New Member
Joined
Mar 29, 2019
Messages
5
Hi -
I've been fiddling with this for a while. Here's what I'm tying to do:
Remove items from a combobox which do not match what the user types into the combobox. Worded differently, I would like the combo to act as a filter which presents matches based on any part of what the user enters.

To duplicate what I'm presently seeing, enter the following values in cells A1:A4:
Code:
A1 Fred Flintstone
A2 Wilma Flintstone
A3 Barney Rubble
A4 Betty Rubble

Set the following properties for the combobox
Name: TempCombo
ColumnCount: 1
ListFillRange: Sheet1!$A$1:$A$4
MatchEntry: 1 - fmMatchEntryComplete

When you enter F, Fr or Fre, the combo will jump to Fred Flintstone, and display Wilma, Barney and Betty as other items in the list.

Similarly, when you enter B, the combo will jump to Barney Rubble and will display Fred, Wilma and Betty as other items in the list.

What I would like to happen:
When you enter F, Fred Flintstone and Wilma Flintstone appear in the list, but Betty and Barney Rubble do not.
When you enter B, Barney and Betty appear as list items, but Fred and Wilma do not.

Similarly, I would like to be able to use any correct sequence of letters for the list item, such as:
ubb or Rub, or Fli, or sto.

Case sensitivity is not important.

So far, I've been playing with the Change event for the control:
Code:
Private Sub TempCombo_Change()
    With TempCombo
        For i = .ListCount = -1 To 0 Step -1
            If Not TempCombo.Text Like "*" & .List(i, 1) & "*" Then .RemoveItem (i)
        Next i
        Stop
    End With
End Sub

When run, I get the following error:
Code:
Could not get the List property. Invalid argument.


The offending line of code is:
Code:
If Not TempCombo.Text Like "*" & .List(i, 1) & "*" Then .RemoveItem (i)


I have tried removing the second parameter like this:
Code:
If Not TempCombo.Text Like "*" & .List(i) & "*" Then .RemoveItem (i)

But the error persists.

What I'd like to know is:
  • What am I doing wrong?
  • Is there a better method?

Thanks for your help!

Thomas
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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