Recording macro to activate other macros

  • Thread starter Thread starter yippy
  • Start date Start date
Y

yippy

Hi all,

I was trying to record a macro that uses other macros that i've already
created. Basically what i wanted to do is to go thru each tab in my
workbook, and run a macro on every sheet. But after recording it, the
macro just go thru the sheet w/o running the macro.

Any help would be great!!
Thanks!!
 
Sub RunOnAllWorksheets()
for each sh in Activeworkbook.Worksheets
sh.Activate
mymacro
Next
End sub

Sub MyMacro()
Range("A1").Select
Selection.Value = "Processed"
End Sub

this runs the macro MyMacro on every sheet in the active workbook.

Make sure your recorded macro doesn't contain code like
worksheets("Sheet1").Activate
If it contains such code it will aways execute the instructions after that
on Sheet1. Comment out statements like that.
 
hi tom,

i should've be more specific, sorry. i do have different macro to ru
on diff sheet. for example, i might be running "AR_10" on the shee
call "AR10". do you have the code for me to specify the sheet name an
macro name?

thanks
 
Try this


Dim sh As Worksheet

Sub test()
For Each sh In ThisWorkbook.Worksheets
mymacro
Next sh
End Sub

Sub mymacro()
sh.Range("a1").Value = 33
End Sub
 
Sub RunOnAllWorksheets()
for each sh in Activeworkbook.Worksheets
sh.Activate
Application.Run left(sh.name,2) & "_" & Mid(sh.name,3)
Next
End sub

will run a macro that takes the sheet name and put an underscore in as a new
character

for AR1 it will run AR_1
for AR10 it will run AR_10
for AR100 it will run AR_100
 
Back
Top