VBA ListBox Search

1952
1
Jump to solution
03-07-2012 11:20 PM
by Anonymous User
Not applicable
Hi,

I'm trying to Search for a string within a listbox but it will only find it if it is the first or last entry in the listbox.  What is the appropriate way to loop through.

For j = 0 To listbox2.listcount -1
value = listbox2.list(j)
next j

If InStr(1, value, "Well") Then  
MsgBox "YES"
End If

Thank  you.
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Try this:

dim blnFound as Boolean blnFound = False  For j = 0 To listbox2.listcount -1     value = listbox2.list(j)    If InStr(value, "Well") Then         blnFound = True    End If next j  If blnFound Then       MsgBox "YES"  End If 

View solution in original post

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor
Try this:

dim blnFound as Boolean blnFound = False  For j = 0 To listbox2.listcount -1     value = listbox2.list(j)    If InStr(value, "Well") Then         blnFound = True    End If next j  If blnFound Then       MsgBox "YES"  End If 
0 Kudos