Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 76
Default How to apply macro across multiple worksheets within a workbook

Hello:

I have a macro in a workbook that I've created on the first worksheet. I
have 11 worksheets in the workbook and the same macro needs to run on each
worksheet.
Is there a way to do it automatically in the original macro or do I have to
run it every time separately on each worksheet.

Please help.
Thank you.

Monika
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 248
Default How to apply macro across multiple worksheets within a workbook

You can use the macro on other sheets also assuming it does not worksheet
level code/procedures...

Steps:
Press ALT-F11 to open the VB Editor
Choose Insert-Module
and paste your macro

Now paste the following after changing testmacro to the name of your macro
sub runOnAllSheets
for each ws in worksheets
call testmacro
next ws
end sub


-------------------------------------
Pl. click ''''Yes'''' if this was helpful...



"murkaboris" wrote:

Hello:

I have a macro in a workbook that I've created on the first worksheet. I
have 11 worksheets in the workbook and the same macro needs to run on each
worksheet.
Is there a way to do it automatically in the original macro or do I have to
run it every time separately on each worksheet.

Please help.
Thank you.

Monika

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default How to apply macro across multiple worksheets within a workbook

Say we have a macro that does stuff on a single sheet (the ActiveSheet)

Sub SingleSheet()
ActiveSheet.Range("A1").Value = "hello world"
End Sub

We want this done on ALL sheets. So we use a loop:

Sub AllTheSheets()
Dim s As Worksheet
For Each s In Worksheets
s.Range("A1").Value = "hello world"
Next
End Sub
--
Gary''s Student - gsnu200844


"murkaboris" wrote:

Hello:

I have a macro in a workbook that I've created on the first worksheet. I
have 11 worksheets in the workbook and the same macro needs to run on each
worksheet.
Is there a way to do it automatically in the original macro or do I have to
run it every time separately on each worksheet.

Please help.
Thank you.

Monika

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 76
Default How to apply macro across multiple worksheets within a workboo

Hello Sheeloo:

Thank you for your help.
Monika

"Sheeloo" wrote:

You can use the macro on other sheets also assuming it does not worksheet
level code/procedures...

Steps:
Press ALT-F11 to open the VB Editor
Choose Insert-Module
and paste your macro

Now paste the following after changing testmacro to the name of your macro
sub runOnAllSheets
for each ws in worksheets
call testmacro
next ws
end sub


-------------------------------------
Pl. click ''''Yes'''' if this was helpful...



"murkaboris" wrote:

Hello:

I have a macro in a workbook that I've created on the first worksheet. I
have 11 worksheets in the workbook and the same macro needs to run on each
worksheet.
Is there a way to do it automatically in the original macro or do I have to
run it every time separately on each worksheet.

Please help.
Thank you.

Monika

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 76
Default How to apply macro across multiple worksheets within a workboo

Thank you for your help Gary
Monika

"Gary''s Student" wrote:

Say we have a macro that does stuff on a single sheet (the ActiveSheet)

Sub SingleSheet()
ActiveSheet.Range("A1").Value = "hello world"
End Sub

We want this done on ALL sheets. So we use a loop:

Sub AllTheSheets()
Dim s As Worksheet
For Each s In Worksheets
s.Range("A1").Value = "hello world"
Next
End Sub
--
Gary''s Student - gsnu200844


"murkaboris" wrote:

Hello:

I have a macro in a workbook that I've created on the first worksheet. I
have 11 worksheets in the workbook and the same macro needs to run on each
worksheet.
Is there a way to do it automatically in the original macro or do I have to
run it every time separately on each worksheet.

Please help.
Thank you.

Monika

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combine worksheets in multiple workbook in one workbook with a macro Sam Commar Excel Discussion (Misc queries) 2 April 2nd 09 01:09 PM
Apply Macro to all worksheets in a workbook except one Carrie_Loos via OfficeKB.com Excel Discussion (Misc queries) 5 January 15th 09 10:03 PM
automatically apply a macro to all worksheets minrufeng Excel Discussion (Misc queries) 5 February 21st 06 09:34 PM
Excel should apply names in all worksheets of a workbook Softball Pete Excel Discussion (Misc queries) 1 January 23rd 06 02:42 PM
apply cell names to formulas in multiple worksheets BBurrows Excel Worksheet Functions 4 July 1st 05 05:35 PM


All times are GMT +1. The time now is 05:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"