ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Recording macro to activate other macros (https://www.excelbanter.com/excel-programming/286944-recording-macro-activate-other-macros.html)

yippy[_2_]

Recording macro to activate other macros
 
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!!


---
Message posted from http://www.ExcelForum.com/


Tom Ogilvy

Recording macro to activate other macros
 
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.

--
Regards,
Tom Ogilvy


"yippy " wrote in message
...
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!!


---
Message posted from http://www.ExcelForum.com/




yippy[_3_]

Recording macro to activate other macros
 
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

--
Message posted from http://www.ExcelForum.com


Ron de Bruin

Recording macro to activate other macros
 
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




--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"yippy " wrote in message ...
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!!


---
Message posted from http://www.ExcelForum.com/




Tom Ogilvy

Recording macro to activate other macros
 
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

--

Regards,
Tom Ogilvy


"yippy " wrote in message
...
hi tom,

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

thanks.


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 09:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com