#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 96
Default Linking Macros

Have workbook with 7 worksheets and run the same macro in each. Can I link
the worksheet macros into one master macro?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Linking Macros

Hi, Diane-
Do you mean you'd like to run the same macro on all seven tabs at
once? If yes, then you can modify the macro with a few extra lines of
code to do that.

Your current macro looks like this:
Sub YourMacroName()
{current code}
End Sub

If you'll modify it to read like this:
Sub YourMacroName()
dim Wksht
For Each Wksht In Sheets
If Wksht.Visible = True Then
Sheets(Wksht.Name).Select

{current code}

End If
Next Wksht
End Sub

This runs the same code on all visible worksheets. With a little more
code you can return the cursor to its original starting point (from
where you launched the macro).

Dave O
Eschew obfuscation
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Linking Macros

Sure. It depends on your goal. Say we have a macro that will run on the
active sheet and we want it to run on each worksheet in the workbook:

Sub slave()
Range("C1").Value = Range("A1").Value + Range("B1").Value
End Sub


Sub master()
For Each w In Worksheets
w.Activate
Call slave
Next
End Sub

The master goes to each sheet and runs the salve on t5hat sheet.
--
Gary''s Student - gsnu200763


"Diane" wrote:

Have workbook with 7 worksheets and run the same macro in each. Can I link
the worksheet macros into one master macro?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 96
Default Linking Macros

Dave,

Got it, but am a little new to the macro editing portion. Can you be a
little more literal in your direction. One of the tabs is called
Construction ~ can you write specifically the code to include this?
Diane

"Dave O" wrote:

Hi, Diane-
Do you mean you'd like to run the same macro on all seven tabs at
once? If yes, then you can modify the macro with a few extra lines of
code to do that.

Your current macro looks like this:
Sub YourMacroName()
{current code}
End Sub

If you'll modify it to read like this:
Sub YourMacroName()
dim Wksht
For Each Wksht In Sheets
If Wksht.Visible = True Then
Sheets(Wksht.Name).Select

{current code}

End If
Next Wksht
End Sub

This runs the same code on all visible worksheets. With a little more
code you can return the cursor to its original starting point (from
where you launched the macro).

Dave O
Eschew obfuscation

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Linking Macros

You mention "worksheet macros".

Do you mean worksheet event code which you have in each sheet's module?

If not, ignore rest of post and look at the other posts.

If, for example each sheet has the same Worksheet_Change code, you can place the
same code into Thisworkbook once and cover all sheets.

Private Sub Workbook_SheetChange _
(ByVal Sh As Object, ByVal Target As Range)

'your code here

End Sub


Gord Dibben MS Excel MVP

On Thu, 3 Jan 2008 08:50:01 -0800, Diane
wrote:

Have workbook with 7 worksheets and run the same macro in each. Can I link
the worksheet macros into one master macro?


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
linking individual macros on the same sheet Quandary 11 - 3 - 07 Excel Discussion (Misc queries) 1 March 11th 07 08:46 AM
Training: More on how to use macros in Excel: Recording Macros ToriT Excel Worksheet Functions 2 February 10th 06 07:05 PM
linking of macros with other workbooks. need to stop it! KyWilde Excel Discussion (Misc queries) 1 March 10th 05 07:13 PM
Linking and/or macros Frustr8 Excel Worksheet Functions 0 January 17th 05 10:27 PM
Macros and Linking Chris Excel Worksheet Functions 0 December 1st 04 04:15 PM


All times are GMT +1. The time now is 01:17 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"