PDA

View Full Version : [SOLVED] How to make a search filter in Excel Userform that displays the output in the ListBox



Stellaaaa
02-04-2019, 09:55 AM
Hi. I'm a complete noob in VBA but I made a UserForm that allows the user to enter a keyword from the Search Box and the result will be displayed on the ListBox. For example, I typed in the word 'car', then the rows from the spreadsheet with the word 'car' in it will be displayed on the ListBox. That's what I am trying to achieve but I don't know how to do it. Can I get some help?

大灰狼1976
02-04-2019, 06:10 PM
for example:

for i=firstrow to lastrow
if cells(i,?)=textbox1 then
r=r+1
for j=1 to lastcolumn
arr(r,j)=cells(i,j)
next j
end if
next i
listbox1.list=arr

Kenneth Hobs
02-04-2019, 06:12 PM
There are three methods that I have used.

1. IF one column, I use an array Filter().
2. If more than one column, I use a scratch sheet and an Autofilter. The number of columns will matter, code-wise.
3. A multiple Find with a paste to a scratch sheet.