VBE313
Well-known Member
- Joined
- Mar 22, 2019
- Messages
- 686
- Office Version
- 365
- Platform
- Windows
I saw this from VBA Express. [FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]http://www.vbaexpress.com/forum/showthread.php?48063-UserFrom-TextBox-search-in-ListBox-in-the-same-UserForm
It was very helpful, I was wondering if you can add error handling if you find no match?
[/FONT]
It was very helpful, I was wondering if you can add error handling if you find no match?
Private Sub TextBox1_Change()Dim i As Long
Dim sFind As String
sFind = Me.TextBox1.Text
If Len(sFind) = 0 Then
Me.ListBox1.ListIndex = -1
Me.ListBox1.TopIndex = 0
Else
For i = 0 To Me.ListBox1.ListCount - 1
If UCase(Left(Me.ListBox1.List(i), Len(sFind))) = UCase(sFind) Then
Me.ListBox1.TopIndex = i
Me.ListBox1.ListIndex = i
Exit For
End If
Next i
End If
End Sub
Thanks
<strike></strike>Dim sFind As String
sFind = Me.TextBox1.Text
If Len(sFind) = 0 Then
Me.ListBox1.ListIndex = -1
Me.ListBox1.TopIndex = 0
Else
For i = 0 To Me.ListBox1.ListCount - 1
If UCase(Left(Me.ListBox1.List(i), Len(sFind))) = UCase(sFind) Then
Me.ListBox1.TopIndex = i
Me.ListBox1.ListIndex = i
Exit For
End If
Next i
End If
End Sub
Thanks
[/FONT]