View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
LuisE LuisE is offline
external usenet poster
 
Posts: 133
Default Search within a ComboBox list

Thanks

"Incidental" wrote:

Hi there LuisE

the code below is one way of doing it though it does use a for/next
loop, just as a point if you are searching for Myname but the combobox
value is myname is will not be found so you have to be searching for
the exact match to the value in the combobox.

Option Explicit
Dim i As Integer
Dim MyVar As String

Function CheckCboBox()

MyVar = "what i'm looking for"

For i = 0 To ComboBox1.ListCount - 1

If ComboBox1.List(i) = MyVar Then

'You can add your code here to use the variable i.e.

MsgBox "hello" & vbNewLine & "I was line " & i & _
" in the combobox"

Exit Function 'Add this to stop searching
'if a name is found

End If

Next i

MsgBox "I was not found boooo to me"

End Function

Hope this helps


Steve