• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Checking the value of a ComboBox from VBA

InExcel 2007 I need to check the value of a ComboBox and execute code differently based on the value selected in the ComboBox.

How do I do that?

Thanks.
0
newbieweb
Asked:
newbieweb
  • 3
  • 2
2 Solutions
 
NorieVBA ExpertCommented:
Where is the combobox located?

To get the value selected you can just use Combobox1.Value, then you could use something like this to decide what to do.
If Me.Combobox1.ListIndex <> -1 Then ' check item has been selected
      Select Case Me.Combobox1.Value
         Case 1
              ' do something
         Case 2 
              ' do something else
         Case 3 
              ' do something completely different
       End Select
Else
      MsgBox "Nothing selected"
End If

Open in new window

This would be for a combobox on a userform or on a worksheet, if ActiveX.

Obviously you'lll need to make changes for your values, the name of the combobox etc.
0
 
newbiewebSr. Software EngineerAuthor Commented:
I don't get it.

Do you need to put the Sheet there? What is Me?

I have the page name by the compiler does not like it.
0
 
newbiewebSr. Software EngineerAuthor Commented:
I don't get why it's always Combobox1.

What if the page has multiple combo boxes??
0
 
NorieVBA ExpertCommented:
What 'page'?

Combobox1 is just an example name, like I said you'll need to change the code to reflect what you actually have.

Me is supposed to reference either a worksheet or userform.

If you can give more information it might help.:)
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now