PC Review


Reply
Thread Tools Rate Thread

Cycle through multiple sheets

 
 
=?Utf-8?B?a2FyaW1oZW1hbmk=?=
Guest
Posts: n/a
 
      19th Mar 2007
Hello all,

Basically I need code to get the names of the sheets so that I can have a
macro cycle through each sheet of a workbook and do the formatting I want.

Each workbook I have has a different number of sheets and each sheet is
named something different. Theres no way I can predict the names of the
sheets. The macro would be run each time a new workbook is opened so I don't
have to worry about the macro going cross-workbooks or opening a different
workbook. Its all done within the same workbook among the various number of
sheets in each workbook.

My initial idea was to somehow get the names of the sheets and put it into
an array. Then use a 'for' loop to cycle through the array and select each
sheet.

But I don't know how to get the list of each sheet or select the next sheet
without knowing the name of the sheet.

Any help or guidance or code samples would be appreciated!

-Karim
 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      19th Mar 2007
Karim,
As with many aspect of the Excel Object Model, you can use the collection of
the desired objects, without knowing each by name.

dim XLWS as Worksheet

For each xlws in thisworkbook.worksheets
debug.print xlws.name 'Whatever you code does
next

NickHK

"karimhemani" <(E-Mail Removed)> wrote in message
news:6EEAD7EC-2D4A-4E02-8E87-(E-Mail Removed)...
> Hello all,
>
> Basically I need code to get the names of the sheets so that I can have a
> macro cycle through each sheet of a workbook and do the formatting I want.
>
> Each workbook I have has a different number of sheets and each sheet is
> named something different. Theres no way I can predict the names of the
> sheets. The macro would be run each time a new workbook is opened so I

don't
> have to worry about the macro going cross-workbooks or opening a different
> workbook. Its all done within the same workbook among the various number

of
> sheets in each workbook.
>
> My initial idea was to somehow get the names of the sheets and put it into
> an array. Then use a 'for' loop to cycle through the array and select each
> sheet.
>
> But I don't know how to get the list of each sheet or select the next

sheet
> without knowing the name of the sheet.
>
> Any help or guidance or code samples would be appreciated!
>
> -Karim



 
Reply With Quote
 
Arvi Laanemets
Guest
Posts: n/a
 
      19th Mar 2007
Hi

.....
For Each ws In Worksheets
... your code here
Next ws
.....


--
Arvi Laanemets
( My real mail address: arvi.laanemets<at>tarkon.ee )



"karimhemani" <(E-Mail Removed)> wrote in message
news:6EEAD7EC-2D4A-4E02-8E87-(E-Mail Removed)...
> Hello all,
>
> Basically I need code to get the names of the sheets so that I can have a
> macro cycle through each sheet of a workbook and do the formatting I want.
>
> Each workbook I have has a different number of sheets and each sheet is
> named something different. Theres no way I can predict the names of the
> sheets. The macro would be run each time a new workbook is opened so I
> don't
> have to worry about the macro going cross-workbooks or opening a different
> workbook. Its all done within the same workbook among the various number
> of
> sheets in each workbook.
>
> My initial idea was to somehow get the names of the sheets and put it into
> an array. Then use a 'for' loop to cycle through the array and select each
> sheet.
>
> But I don't know how to get the list of each sheet or select the next
> sheet
> without knowing the name of the sheet.
>
> Any help or guidance or code samples would be appreciated!
>
> -Karim



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i set up attendance sheets for 2 week repeting work cycle bill Microsoft Excel Misc 0 5th Jan 2009 02:58 PM
crtl + page down or up does not cycle through sheets in excel 2007 John G. Microsoft Excel Misc 4 8th May 2008 05:21 PM
Update sheets & cycle Sinner Microsoft Excel Programming 2 2nd Mar 2008 10:34 PM
Multiple Sheets (Need to create 500 individual sheets in one workbook, pulling DATA Amaxwell Microsoft Excel Worksheet Functions 4 17th Aug 2006 06:23 AM
Help with copying data from multiple sheets to multiple sheets Randy Reese Microsoft Excel Programming 1 18th Mar 2004 10:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:18 AM.