Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Execute Module on Drop down selection

Posted on 2011-03-18
5
Medium Priority
?
230 Views
Last Modified: 2012-05-11
I have a ActiveX Control Dropdown box.
I also have a module named "filtercode" that takes the value selected in that box (linked to another cell within the same sheet) that filters a dataset by a certain field, based on the value i select.

How or with what code do i need to execute this 'filtercode' upon selecting a selection from the drop down menu? So for example, if I select "John" from the drow down, i want the filtercode module to automatically run.
0
Comment
Question by:ctownsen80
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:SmittyPro
ID: 35168087
You can use the ComboBox's Change event to call the code.  Or if you want to use Data Validation instead of a control you can use a Change event:

Private Sub Worksheet_Change(ByVal Target As Range)
    '   Code goes in the Worksheet specific module
    Dim rng As Range
        '   Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
        Set rng = Target.Parent.Range("xxx")
             '   Only look at single cell changes
            If Target.Count > 1 Then Exit Sub
            '   Only look at that range
            If Intersect(Target, rng) Is Nothing Then Exit Sub
            '   Action if Condition(s) are met (do your thing here...)
            
End Sub

Open in new window


HTH

0
 

Author Comment

by:ctownsen80
ID: 35168243
Thahnks for your response @ SmittyPro.


I need a little more direction. The cell that will change is cell "BQ2". Upon change in cell BQ2, i want to execute module "filtercode". Can you adjust code you provided to how that would be embedded?
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35168306
There are a couple other alternatives:

1 - create a dropdown control, with cell link - use an index from that link to determine what was selected, and link that dropdown to a macro
2 - create an active-x control, and write code behind that control when items are selected.

Both are in the attached spreadsheet.  Please advise if further assistance is needed.

Give it a try!  when you make a selection from either example, the hello subroutine I wrote will advise you with a messagebox what you selected - that's where you can take action based on what was selected

Dave
DropDownList-Action-r1.xls
0
 
LVL 4

Accepted Solution

by:
SmittyPro earned 1000 total points
ID: 35168377
For the change event, assuming you use Data Validation, you would set the target range:

Set rng = Target.Parent.Range("BQ2")

And at the bottom under the "Do your thing here" part you'd add:

Call filtercode
0
 

Author Closing Comment

by:ctownsen80
ID: 35168512
Got it working! Thanks for your help!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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.

876 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