Hello everyone,
I need help with my code. I have a listbox in my userform that displays all the data in Sheet1. From the userform the user can select a row and then Delete/Add new rows and edit existing rows. Given this i want to make a filter where the user can search for a word and it will show only the rows that have that word. For example if you search for a serial number of a item it will show you only the row where that or those items are so the user can then delete or edit that row.
I managed to make the code highlight when you search but i only managed to do it if you search words that are present in the first column and i've been stuck ever since.
Any help would be appreciated.
Code:
I need help with my code. I have a listbox in my userform that displays all the data in Sheet1. From the userform the user can select a row and then Delete/Add new rows and edit existing rows. Given this i want to make a filter where the user can search for a word and it will show only the rows that have that word. For example if you search for a serial number of a item it will show you only the row where that or those items are so the user can then delete or edit that row.
I managed to make the code highlight when you search but i only managed to do it if you search words that are present in the first column and i've been stuck ever since.
Any help would be appreciated.
Code:
VBA Code:
Private Sub txtsearch_Change()
'searches lstdisplay for match and hightlights result. Need to filter results.
Dim i As Long
Dim sFind As String
sFind = Me.txtsearch.Text
If Len(sFind) = 0 Then
Me.lstDisplay.ListIndex = -1
Me.lstDisplay.TopIndex = 0
Else
For i = 0 To Me.lstDisplay.ListCount - 1
If UCase(Left(Me.lstDisplay.List(i), Len(sFind))) = UCase(sFind) Then
Me.lstDisplay.TopIndex = i
Me.lstDisplay.ListIndex = i
Exit For
End If
Next i
End If
End Sub