ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Programmatically addressing worksheets - painfully stupid question (https://www.excelbanter.com/excel-programming/276358-re-programmatically-addressing-worksheets-painfully-stupid-question.html)

Chip Pearson

Programmatically addressing worksheets - painfully stupid question
 
Chris,

You can do something like

Dim WS As Worksheet
For Each WS In Worksheets
WS.Cells.....
Next WS

or

Dim N As Long
Dim WS As Worksheet
For N = 1 To 53
Set WS = Worksheets("Week" & Format(N,"#0")
WS.Cells....
Next N

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"Chris Strug" wrote in message
...
Hi,

Probably a simple one but I can't seem to get the correct syntax.

I have a workbook containing a worksheet for every week of the year. Each
worksheet needs a degree of formatting that I don't want to do by hand -

for
example, print setup.

What I'd like to do is to create a macro that will cycle through every
worksheet performing the commands I'd like.

For example,

for i = 1 to 53
worksheets("Week" & format(i,"#0")).select
worksheets.cells...
.
.
.
next i

For the life of me I can't get the right syntax. Can someone please point

me
in the right direction.

Kind thanks

Chris Strug.





Chris Strug

Programmatically addressing worksheets - painfully stupid question
 

"Chip Pearson" wrote in message
...
Chris,

You can do something like

Dim WS As Worksheet
For Each WS In Worksheets
WS.Cells.....
Next WS

or

Dim N As Long
Dim WS As Worksheet
For N = 1 To 53
Set WS = Worksheets("Week" & Format(N,"#0")
WS.Cells....
Next N

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com



Chip,

Many thanks. I can never get my head around collections of objects - pity
they seem so useful!

Thanks again

CS




All times are GMT +1. The time now is 12:06 PM.

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