Run Macro from a list

O

OsmoseTom

I have a data validation list in cell B2. The list consists of two choices
(Year, Month). Based on the users selection I would like to run a macro.
The maros are named Year and Month.
 
R

RyanH

I would try using the Change Event. Maybe something like this is what you
are asking for:

Sub Combox1_Change()

Select Case Combox1.Value

Case Is = "2008, Mar"
Call Macro1
Case Is = "2008, Jan"
Call Macro2
Case Is = "2007, Dec"
Call Macro3

End Select

End Sub
 
G

Gary''s Student

Try the following event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set b2 = Range("B2")
Set t = Target
If Intersect(t, b2) Is Nothing Then Exit Sub
v = b2.Value
If v = "Year" Then
Call yearr
Else
Call monthh
End If
End Sub

Note: I changed the spelling of the called routines to avoid ambiguities.
 
B

Bob Phillips

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

Application.Run .Value
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.
 
O

OsmoseTom

Gary,

You are a genius, I have been struggling with this for hours. Your code
worked great.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top