running a macro within anohter macro in Excel

P

Pat

I have 2 macros written. I would like to
press Alt G for example and have it run
Alt F followed by additonal instructions.
Both macros work fine independently, but
I want to execute both with the button I
have set up for one.

Thanks!!
 
J

J.E. McGimpsey

One way:

Public Sub Macro1()
'Alt-F
MsgBox "Macro1"
End Sub

Public Sub Macro2()
MsgBox "Macro2"
End Sub

Public Sub Macro3()
'Alt-G
Macro1
Macro2
End Sub

or, if you're never going to run Macro2 independently, just:

Public Sub Macro2()
'Alt-G
Macro1
MsgBox "Macro2"
End Sub
 
N

Neil Bhandar

You can also try calling a subroutine in JEM's example

Call Macro1
Call Macro2

-Neil
 
J

J.E. McGimpsey

Call is implied, in this case:

Public Sub Macro1()
Macro2
End Sub

and

Public Sub Macro1()
Call Macro2
End Sub

are functionally identical.
 
Top