Solved

Checking the value of a ComboBox from VBA

Posted on 2011-09-08
5
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 34

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 34

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Outlook Free & Paid Tools
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

751 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