Saturday, January 16, 2016

How to find item in listbox in VBA



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Private Sub CommandButton1_Click()
Dim i As Long
    If TextBox1.Text = "" Then Exit Sub
    For i = 0 To ListBox1.ListCount - 1             ''(1)
        If ListBox1.List(i) = TextBox1.Text Then    ''(2)
            ListBox1.ListIndex = i                  ''(3)
            MsgBox "found in index " & ListBox1.ListIndex
            Exit Sub
        End If
    Next i
    MsgBox "not found"
End Sub


Download File

No comments :

Post a Comment