Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Have workbook with 7 worksheets and run the same macro in each. Can I link
the worksheet macros into one master macro? |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
linking individual macros on the same sheet | Excel Discussion (Misc queries) | |||
Training: More on how to use macros in Excel: Recording Macros | Excel Worksheet Functions | |||
linking of macros with other workbooks. need to stop it! | Excel Discussion (Misc queries) | |||
Linking and/or macros | Excel Worksheet Functions | |||
Macros and Linking | Excel Worksheet Functions |