Filtering a Listbox with a textbox in a userform

ArisZ

New Member
Joined
Jun 1, 2014
Messages
29
Hey all. I have been trying for days, read other posts, and can't get this to work.

I have a user form. On this form there is a listbox named Values. This box has it's data RowSource set to 'Costsrt'!B5:B1171.
I have a TextBox above it labeled Search_Box.

What I want, is being that I have 1166 entries, to be able to type into the search box, and as I type, it will only keep the lines that include
what I am typing. So if I type safety for example, then the only lines it should show are lines that contain the word safety in it.

Can anyone help me with this? I tried and can't get it to work.

Also, I see a lot of posts saying to use the command line Me.RefreshList

If I put this in, I always get an error. Is this an old line? After Me. I don't even have that as a valid choice.

Thanks in advance!!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Clear the RowSource property of the list and use something like this:
Code:
Private Sub Search_Box_Change()
    Dim vList
    vList = Application.Transpose(Me.Values.List)
    Me.Values.List = Filter(vList, Search_Box.Text)
End Sub


Private Sub UserForm_Initialize()
    Me.Values.List = Sheets("Costsrt").Range("B5:B1171").Value
End Sub
 
Upvote 0
That's spookily close to mine on EF, though I reckon mine is a bit more efficient ;p

Code:
Dim data


Private Sub TextBox1_Change()
    Me.ListBox1.List = Filter(data, Me.TextBox1.Text)
End Sub


Private Sub UserForm_initialize()
    data = Application.Transpose(Sheets("Costsrt").Range("B5:B1171").Value)
    Me.ListBox1.List = data
End Sub
 
Upvote 0
This works well as long as the list box is only one column. I would like to display multiple columns in my listbox, but when I change the rage for the listbox to include more columns, it causes a type-mismatch when I try to run the search. How do I display multiple columns without causing an error?

Also, I noticed if I make a typo in the textbox and back space, the listbox filter does not refresh back to before the typo. is it possible to have the list refresh with any changes?

Thank you in advance for any help!
 
Upvote 0

Forum statistics

Threads
1,215,193
Messages
6,123,560
Members
449,108
Latest member
rache47

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