Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
.AddItem list and populating combobox with created list pallaver Excel Discussion (Misc queries) 8 June 27th 08 12:36 PM
Combobox list to leave ONLY related values in list ?? Corey Excel Programming 2 January 4th 07 09:13 PM
Combobox List to list Numerical Values ONLY in Column A is specific Sheet.... Corey Excel Programming 5 December 28th 06 10:40 AM
Combobox exit event search error Craig[_24_] Excel Programming 5 May 9th 06 06:55 PM
ComboBox list reliant on the entry from a different ComboBox ndm berry[_2_] Excel Programming 4 October 4th 05 04:40 PM


All times are GMT +1. The time now is 04:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"