Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Checking the value of a ComboBox from VBA

Posted on 2011-09-08
5
Medium Priority
?
170 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 2000 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 2000 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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…

705 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