Solved

Execute Module on Drop down selection

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

815 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

13 Experts available now in Live!

Get 1:1 Help Now