Running Macro/VBA in multiple worksheets.
Bob,
I'm not sure if you reviewed the reply I sent to Gary but basically I had
the same result with your suggestion. The Marco ran 7 times which I assume
was 1 for each Worksheet in the Workbook. It doesn't seem to be switching to
the other Worksheets.
Any other thoughts/suggestions are welcome.
Thanks.
--
SHD
"Bob Phillips" wrote:
For Each sh In ActiveWorkbook.Worksheets
Call MyMacro
Next sh
You might need to pass the sh object to the macro so that it can work on
that, like this
For Each sh In ActiveWorkbook.Worksheets
Call MyMacro(sh)
Next sh
Sub MyMacro(pSheet as worksheet)
With pSheet
'...
End With
End Sub
--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
"YellowBird" wrote in message
...
I am trying to run a Macro (which works perfectly) in "All" Worksheets of
a
particular Workbook. I currently have seven Worksheets in the Workbook
and
have to select each Worksheet and manually run the Macro. I will
eventually
have 50 (maybe more) Worksheets where the Macro will need to be run. I
have
used the "Private Sub" code in VBA but can only get it to execute the
Macro
in the active Worksheet when the Workbook opens.
Is there code that could/would run the Macro in "All" the Sheets? Sheet1,
Sheet2, Sheet3, Sheet4.
Any help would be greatly appreciated.
--
SHD
|