filter listbox on Userform

  • Thread starter Thread starter MarMo
  • Start date Start date
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
 
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
 
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
 
Back
Top