Hello all!
How do I filter the data in ListBox1 using text entered in TextBox1?
eg. enter "o" will focus on first string start with "o" in ListBox.
Thanks.
Hello all!
How do I filter the data in ListBox1 using text entered in TextBox1?
eg. enter "o" will focus on first string start with "o" in ListBox.
Thanks.
Try something like this.
Private Sub CommandButton1_Click() Dim i As Long Dim n As Long Dim Str As String Str = Me.TextBox1.Text n = Me.ListBox1.ListCount For i = 0 To n - 1 If Left(Me.ListBox1.List(i), Len(Str)) = Str Then Me.ListBox1.ListIndex = i Exit Sub End If Next i End Sub
You could also put this code on the change event for the TextBox.
Private Sub TextBox1_Change() Dim i As Long Dim n As Long Dim Str As String Str = Me.TextBox1.Text n = Me.ListBox1.ListCount For i = 0 To n - 1 If Left(Me.ListBox1.List(i), Len(Str)) = Str Then Me.ListBox1.ListIndex = i Exit Sub End If Next i End Sub
Thanks, Killian!
Is there anywhere that I can focus that filtered data at the uppermost part of that region?
eg. Type 'o' in tb.
ListBox1 (requirement that i need)
......
orange <-----
mango
apple
......
this type is ur code output, very good!
(but not I want to implement )...
ListBox1
.......
apple
mango
orange <-----
........
Thanks. Anyone can help?
Or a better idea here...Filter and show only those data start with 'o' (example on top)
ListBox1 (only show two data [all with o] in the listbox)
orange <-----
oxygen
thanks.
Can anyone have other ideas on implement filter options on Userform1.ListBox1 ? My seems not working....
Thanks.
If you have Visual Studio tools for MS Office, then it would be easier to do what you'd like to do. If not, the easiest workaround that I see is to convert your listbox to a combobox, since you want combobox behavior on your listbox.
It might not look as good, but functionality always outweighs aesthetics--unless you're doing work for graphic designers.
Thanks for helping. Now i know a more bout functionality.functionality always outweighs aesthetics
Sorry for posting again. I really need to know how to filter the ListBox (the selected first data at the top of list box)?Originally Posted by sheeeng
Does anyone have ideas?
Can share with me?