Solved

Checking the value of a ComboBox from VBA

Posted on 2011-09-08
5
154 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now