ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping Thru Worksheets (https://www.excelbanter.com/excel-programming/387294-looping-thru-worksheets.html)

Jay

Looping Thru Worksheets
 
I have a chunk of code that I would like to run thru on only certain
worksheets. How do I loop thru say only Sheets 2-6?

PCLIVE

Looping Thru Worksheets
 
Worksheets are numbered from left to right regardless of their names.


Method One:

for i = 2 to 6
sheets(i).select
<Your Code
next i


Method Two (preferred due to unknowns such as hidden sheets):

for i = 2 to 6
sheets("Sheet" & i).select
<Your Code
next i


HTH,
Paul

"Jay" wrote in message
...
I have a chunk of code that I would like to run thru on only certain
worksheets. How do I loop thru say only Sheets 2-6?




Bob Phillips

Looping Thru Worksheets
 
For Each Sh In
Worksheets(Array("Sheet2","Sheet3","Sheet4","Sheet 5","Sheet6"))
'do something
Next sh

--
HTH

Bob

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

"Jay" wrote in message
...
I have a chunk of code that I would like to run thru on only certain
worksheets. How do I loop thru say only Sheets 2-6?





All times are GMT +1. The time now is 05:16 AM.

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