Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search within a ComboBox list
I need to determine if a given number is in a ComboBox list; if so Ill
trigger an action. Any chance to use IF statements?, Doing a For/Next loop seems not to capture it. Thanks in advance |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Search within a ComboBox list
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
.AddItem list and populating combobox with created list | Excel Discussion (Misc queries) | |||
Combobox list to leave ONLY related values in list ?? | Excel Programming | |||
Combobox List to list Numerical Values ONLY in Column A is specific Sheet.... | Excel Programming | |||
Combobox exit event search error | Excel Programming | |||
ComboBox list reliant on the entry from a different ComboBox | Excel Programming |