Solved

Execute Module on Drop down selection

Posted on 2011-03-18
5
221 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 41

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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

911 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

21 Experts available now in Live!

Get 1:1 Help Now