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

x
?
Solved

Execute Module on Drop down selection

Posted on 2011-03-18
5
Medium Priority
?
229 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
[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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

704 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