Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Looping Through Worksheets In A Workbook

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Looping Through Worksheets In A Workbook

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

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Steve" wrote in message link.net...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Looping Through Worksheets In A Workbook

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

-----Original Message-----
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


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Looping Through Worksheets In A Workbook

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

--
Regards,
Tom Ogilvy

"Steve" wrote in message
link.net...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
looping a calculation until workbook closes tjb Excel Worksheet Functions 0 April 22nd 05 07:06 PM
macro to browse for workbook, pick up data and looping uriel78 Excel Worksheet Functions 1 March 10th 05 12:37 PM
VBA code for looping through open workbooks and worksheets Jamie Martin[_2_] Excel Programming 1 July 24th 03 06:44 PM
looping through worksheets Alex ekster Excel Programming 1 July 21st 03 03:16 AM
looping through worksheets alex Excel Programming 0 July 20th 03 06:43 PM


All times are GMT +1. The time now is 02:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"