Applying same macro to all worksheets in workbook

  • Thread starter Thread starter jsadd1
  • Start date Start date
J

jsadd1

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
 
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
 
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
 
Back
Top