Solved

Checking the value of a ComboBox from VBA

Posted on 2011-09-08
5
158 Views
Last Modified: 2012-05-12
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
Comment
Question by:newbieweb
  • 3
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 36505860
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
 

Author Comment

by:newbieweb
ID: 36506157
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
 

Author Comment

by:newbieweb
ID: 36506207
I don't get why it's always Combobox1.

What if the page has multiple combo boxes??
0
 
LVL 33

Assisted Solution

by:Norie
Norie earned 500 total points
ID: 36506438
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
 

Author Closing Comment

by:newbieweb
ID: 36524143
Thanks!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My experience with Windows 10 over a one year period and suggestions for smooth operation
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question