Search Listbox Values

  • Thread starter Thread starter kylekelsch
  • Start date Start date
K

kylekelsch

I have a TextBox and a ListBox. My question is Is there a way to
search through the values in the listbox to see if the value entered
in the textbox exists in the Listbox?
 
here's one way:

Sub test()
Dim i As Integer

For i = 0 To ListBox1.ListCount - 1
If TextBox1.Text = ListBox1.List(i) Then
MsgBox TextBox1.Text & " exists in listbox"
Exit Sub
End If
Next i

MsgBox TextBox1.Text & " does not exist in listbox"

End Sub
 
Back
Top