ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Applying same macro to all worksheets in workbook (https://www.excelbanter.com/excel-discussion-misc-queries/51284-applying-same-macro-all-worksheets-workbook.html)

[email protected]

Applying same macro to all worksheets in workbook
 
HI,

I am trying to find an easy way to apply a macro that changes the
absolute value of a couple of cells and changes some plot formatting to
all sheets in a workbook. All sheets are the same and need the same
macro applied to them, I have recorded the macro such that I can click
on a worksheet and hit a keyboard command to execute this, but I have
to individually select each worksheet and repeat this throughout, how
can this be automated?

Thanks,

Josh


Jezebel

Applying same macro to all worksheets in workbook
 
Rewrite the macro so it takes a worksheet as an argument. Then write a
second macro that iterates your worksheets and passes them one at a time to
your first macro.

Dim pSheet as Excel.WorkSheet

For each pSheet in ActiveWorkbook.Sheets
MyMacro pSheet
Next





wrote in message
oups.com...
HI,

I am trying to find an easy way to apply a macro that changes the
absolute value of a couple of cells and changes some plot formatting to
all sheets in a workbook. All sheets are the same and need the same
macro applied to them, I have recorded the macro such that I can click
on a worksheet and hit a keyboard command to execute this, but I have
to individually select each worksheet and repeat this throughout, how
can this be automated?

Thanks,

Josh




Gary''s Student

Applying same macro to all worksheets in workbook
 
This macro moves through each worksheet in a workbook and sums the first cell:

Sub Macro1()
Dim w As Worksheet
t = 0
For Each w In Worksheets
w.Activate
t = t + Cells(1, 1)
Next
MsgBox (t)
End Sub

Adapt it to your needs
--
Gary's Student


" wrote:

HI,

I am trying to find an easy way to apply a macro that changes the
absolute value of a couple of cells and changes some plot formatting to
all sheets in a workbook. All sheets are the same and need the same
macro applied to them, I have recorded the macro such that I can click
on a worksheet and hit a keyboard command to execute this, but I have
to individually select each worksheet and repeat this throughout, how
can this be automated?

Thanks,

Josh




All times are GMT +1. The time now is 11:13 PM.

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