ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Run a macro on multiple worksheets? (https://www.excelbanter.com/excel-discussion-misc-queries/128927-run-macro-multiple-worksheets.html)

J@Y

Run a macro on multiple worksheets?
 
Say I have a macro that reverses the order of a list. I have the identical
list in 5 sheets in a workbook. I tried to select all the sheets and running
the macro, but it only runs it on the worksheet I'm looking at.

Bob Phillips

Run a macro on multiple worksheets?
 

For Each sh In Sheets(Array("Sheet1", "Sheet2",
"Sheet3","Sheet4","Sheet5"))
myMacro sh
Next sh

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"J@Y" wrote in message
...
Say I have a macro that reverses the order of a list. I have the identical
list in 5 sheets in a workbook. I tried to select all the sheets and

running
the macro, but it only runs it on the worksheet I'm looking at.




J@Y

Run a macro on multiple worksheets?
 
I'm new to scripting, what exactly is "sh" and "myMacro?

"Bob Phillips" wrote:


For Each sh In Sheets(Array("Sheet1", "Sheet2",
"Sheet3","Sheet4","Sheet5"))
myMacro sh
Next sh

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"J@Y" wrote in message
...
Say I have a macro that reverses the order of a list. I have the identical
list in 5 sheets in a workbook. I tried to select all the sheets and

running
the macro, but it only runs it on the worksheet I'm looking at.





Bob Phillips

Run a macro on multiple worksheets?
 
sh is a variable which can be left undeclared but better is to declare as
type Worksheet

Dim sh As Worksheet

myMacro is the macro that you said that you have.

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"J@Y" wrote in message
...
I'm new to scripting, what exactly is "sh" and "myMacro?

"Bob Phillips" wrote:


For Each sh In Sheets(Array("Sheet1", "Sheet2",
"Sheet3","Sheet4","Sheet5"))
myMacro sh
Next sh

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my

addy)

"J@Y" wrote in message
...
Say I have a macro that reverses the order of a list. I have the

identical
list in 5 sheets in a workbook. I tried to select all the sheets and

running
the macro, but it only runs it on the worksheet I'm looking at.








All times are GMT +1. The time now is 10:17 PM.

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