Looping Through Worksheets In A Workbook

S

Steve

I have a workbook with 12 worksheets named Jan-03 to Dec-03. What would be the
code to start at the first worksheet and loop through all the worksheets making
each worksheet active one at a time, doing some processing on the active
worksheet and then going to the next worksheet?

Thanks for your help!

Steve
 
R

Ron de Bruin

Sub test()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
'sh.Select
sh.Range("a1").Value = 30
Next sh
End Sub

Remember in the most cases you don't have to activate /select the worksheet or cells
 
P

Pete McCosh

Steve,

this should do the trick. Just remember, when you are
referring to properties/ranges inside the loop, they are
properties of the wksht object, not a sheets object.

Sub StevesSheets ()
Dim wksht as Worksheet

For Each wksht in ActiveWorkBook.Worksheets
'... Steve's Code here...'
Next wksht

End Sub

Cheers, Pete
 
T

Tom Ogilvy

Dim sh as Worksheet
for each sh in Worksheets
sh.Activate
' process sheet
Next
 
Top