Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

search for wildcard value within the third column in a userform listbox vba

Now I need to do a wildcard search.

previous question: looking for a single value
https://www.experts-exchange.com/questions/28120171/search-for-value-within-the-third-column-in-a-userform-listbox-vba.html


Now i need to search for value within the text in the third column ?

So the listbox has 20 rows in it..

In column 3 i need to search for the value "Hammer"

But the column 3 text could be as follows:

"Rip Claw Hammer"
"Striking Hammer"
"Ball Pein Hammers"
"Screwdriver 9 inch phillips head"
"Hammer, Claw 8oz"

So if i search for "Hammer"
"Rip Claw Hammer"
"Striking Hammer"
"Ball Pein Hammers"
"Hammer, Claw 8oz"

The listbox changes to these results

Thanks
fordraiders
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Change my code to

Private Sub CommandButton1_Click()
Dim strFilter As String
Dim lngIndex As Long

strFilter = InputBox("Which color?")

For lngIndex = ListBox1.ListCount - 1 To 0 Step -1
    If InStr(1, ListBox1.List(lngIndex, 2), strFilter) = 0 Then
        ListBox1.RemoveItem (lngIndex)
    End If
Next

End Sub

Open in new window

Avatar of Fordraiders

ASKER

this does a wildcard search in column 3 ?
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013