filter listbox on Userform

M

MarMo

Hi all ,
I would like to do the following :
1) Filter a listbox using a textbox , which means that if i put a string
into the textbox i'd like to see only the filtered data in the listbox
OR
2) Search data in the range of cells and select the corresponding row in the
listbox.
Is there a way to do this.
I alredy searched the net but without results so , I'm open to all
suggestions.

Many Thanks
MarMo
 
T

Tom Ogilvy

Perhaps something like this:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim rng as Range, cell as Range
with worksheets("Sheet1")
set rng = .Range(.Cells(2,1),.Cells(2,1).End(xldown))
End with
Listbox1.Clear
for each cell in rng
if instr(1,cell,Textbox1.Value,vbTextcompare) then
ListBox1.AddItem cell.Value
end if
Next
End Sub
 
M

marmo

Hello Tom ,

Thanks for responding .

MarMo

Tom Ogilvy said:
Perhaps something like this:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim rng as Range, cell as Range
with worksheets("Sheet1")
set rng = .Range(.Cells(2,1),.Cells(2,1).End(xldown))
End with
Listbox1.Clear
for each cell in rng
if instr(1,cell,Textbox1.Value,vbTextcompare) then
ListBox1.AddItem cell.Value
end if
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top