Run a macro when a cell changes

M

mjb2005

Hello
I'm just having a really bad day I guess. I was wondering if some kind
soul could help.
I have created 12 macros called pastejanuary, pastefebruary, pastemarch
etc etc etc. These are pastespecial operations.
What I would like to do is if the cell $g$1 changes from january to
february, run the macro called pastefebruary.
Any ideas would be greatly appreciated. I created private sub
worksheet_change(by val target as excel range and then asked for the
range $g$1 and range value of February but thats where I ran into
trouble.
I cannot for the life of me get it to run the pastefebruary macro.

I really would appreciate any help you could give me
Cheers
 
M

mjb2005

Thanks Anne
I did try this earlier on but I probably should have been a bit clearer
for everyone in that I don't really want to run just one macro because
(maybe a bit stupidly) I have created 12 different macros for each
month and when the month changes say to March, I only want to run the
March Macro.
Clear as mud?
Thanks again
 
B

Bob Phillips

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("G1")) Is Nothing Then
With Target
Select Case LCase(.Value)
Case "january": PasteJanuary
Case "february": PasteFebruary
'etc.
End Select

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.


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)
 
M

mjb2005

Dear Bob
I must thank you so much. I am new to vb and even though I was sort of
on the right track, I just couldn't get the old grey matter around it.
I really appreciate your help
Thank you again
Marlene
 

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