PDA

View Full Version : Visual Basic listbox search function



TimdeBlaeij
07-14-2017, 06:49 AM
Hi,

Im trying to make a search function for my listbox. I want it to happen in the following way:
When you type in the textbox txbSearch, all rows that have nothing to do with the search text are removed from the listbox or are invisible.
If possible i want the search function to search all columns at once.
My listbox is currently set up in the following way:

Set r = Range("T1").CurrentRegion
Set r = r.Offset(1).Resize(r.Rows.Count - 1)
With Lsb1
.ColumnCount = r.Columns.Count
.RowSource = r.Address
.ColumnHeads = True
End With

Does anybody know how to do this?

Thanks in advance

mana
07-16-2017, 06:01 AM
1)You want to display column header? You can use label as a substitute.

2)Only remove data? you don't need to add data?

3)Do you know ListView control?

TimdeBlaeij
07-16-2017, 11:04 PM
Yeah I do want to display the column header. It works just the way I want it to.

I don't need to add data.

I can't seem to find this Listview control. What is it?

mdmackillop
07-17-2017, 03:01 AM
There are 3 possibilities I can see to do it as previously as hiding rows in the source is not an option:
1. Make an edited copy of the table and display that on the userform (or a similar one)
2. Delete the rows from the table
3. Move the rows to the bottom of the table
Could any of these work for you? (not knowing what your form is intended to do)

TimdeBlaeij
07-17-2017, 03:54 AM
My form is supossed to display columns which give information about articles. Each row holds one article.
I think the best way to do this is to temporary remove the rows that do not have anything in common with the search text.
Do you have an idea on how I can do this?