Refill combo box with possible matches based on User's input

JST013

Board Regular
Joined
Mar 11, 2015
Messages
74
A little baffled here at what I am seeing.... for some reason the following code will add duplicates (and sometimes even more) to my combo box of the names it finds a matching letter of...


Let me explain. The following code is supposed to activate whenever the combo box value changes...(I have set the Matchentry property to MatchEntryNone)..It is supposed to take that change and refill my combo box with values that have the text anywhere in them.

So if my box is filled with...

"Adam Spencer"
"Jonny Applesauce"
"Ceasar Milan"
"Tony Yolo"
(Not sure if it would match to the capital A, but that's not the problem anyway...)
The code should adjust the box to exclude "Tony Yolo" because he doesn't have an "a" anywhere in his name.

The reason I am baffled is because the code works perfectly when I step through it...but when I'm testing the userform it will do the doubles and triples...It does get the correct values but it will double them up.


Code:
Private Sub cbName_Change()
cbcoll.Clear
With Me.cbName
    For thing = 0 To Me.cbName.ListCount - 1


        cbcoll.Add Me.cbName.List(thing)


    Next
    FilterComboBox1 Me.cbName.Text


End With


End Sub
Public Sub FilterComboBox1(strFilter As String)
    Me.cbName.Clear


    For Each strChoice In cbcoll
        If InStr(1, strChoice, strFilter) <> 0 Then
            Me.cbName.AddItem strChoice
        End If
    Next

End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,214,570
Messages
6,120,296
Members
448,954
Latest member
EmmeEnne1979

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