Data Validation help

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi all

Cell F5 in my Data sheet holds a drop down populated by range AA9:AA13 (Data validation - list )

When a selection is chosen from this menu I want a certain 'event' to happen

so AA9:AA13 holds

Car
Bus
Train
Plane
Bike


so if Bike is chosen then run macro "bike"
if plane is chosen run macro "plane" ...etc

any ideas how to get this to happen??

many thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "F5" Then Application.Run Target.Value
End Sub
 
Upvote 0
Hi VoG

But how does your example know which of my macros to run depending on which is selected from the data validation list?
 
Upvote 0
VoG

I'm sorry I still don't understand.....

I have right clicked the sheet tab, selected View Code and pasted in
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "F5" Then Application.Run Target.Value
End Sub

When I click on cell F5 I have a chose from the drop down menu..

Dog
Cat
Plane
Car
Boat

if I select Dog from this I want the "Dog" macro to run etc etc

but using ur code above nothing happens when I chose from the validation box in F5..

Sorry :eeek:
 
Upvote 0
I just tested it and it works fine.

Make sure your Dog, Cat etc. subs are in a regular module. Make sure that events are enabled. Press CTRL+G, type in

Application.EnableEvents=True

and press Enter.
 
Upvote 0
getting there....

In module2 I have

Code:
Sub Dog()
MsgBox "ruff"
End Sub
Sub Cat()
MsgBox "Meow"
End Sub
Sub Plane()
MsgBox "Woooosh"
End Sub
Sub Car()
MsgBox "Vrooom"
End Sub
Sub Boat()
MsgBox "Whoop Whoop"
End Sub
I have also enabled the events and now
Code:
Application.EnableEvents=True
is sitting in the immediate box

When I go back to my sheet and select any of the drop menu all works fine apart from the Dog..I get an error saying Dog Macro can't be found??
 
Upvote 0
Make sure that in your data validation list it is actually "Dog" not " Dog" or "Dog ".

You can close the Immediate window.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top