PC Review


Reply
Thread Tools Rate Thread

Creating a collection of visible worksheets

 
 
Rich
Guest
Posts: n/a
 
      26th Mar 2009
I need to search for data contained on certain worksheets. My current method
is this:

dim wks as worksheet
For Each wks in ThisWorkbook.Worksheets
if wks.name like "Data (*)" and wks.visible = xlSheetVisible
***now I collect my data***
......

My question is....
I have quite a few pages (15 to 18 min...maybe more) that are hidden, but I
have to cycle thru them because they are part of "ThisWorkbook". Although
this really does not take much time, I'd like to have a cleaner way. Is
there a simple way of creating a collection of only the VISIBLE worksheets in
the ThisWorkbook - thus reducing the number of worksheets I need to iterate
thru in the "For Each" loop??

Taking it a step further....creating a collection of visible worksheets
whose name matches the criteria I define??

Thanks!!!
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      26th Mar 2009
Your question is a little confusing, since the code you posted does
eliminate the hidden sheets. It probably takes a gigasecond for the
compiler to see that a sheet is not visible with the code currently used.


"Rich" <(E-Mail Removed)> wrote in message
news:1F3F1EFA-991B-4B08-BC15-(E-Mail Removed)...
>I need to search for data contained on certain worksheets. My current
>method
> is this:
>
> dim wks as worksheet
> For Each wks in ThisWorkbook.Worksheets
> if wks.name like "Data (*)" and wks.visible = xlSheetVisible
> ***now I collect my data***
> .....
>
> My question is....
> I have quite a few pages (15 to 18 min...maybe more) that are hidden, but
> I
> have to cycle thru them because they are part of "ThisWorkbook". Although
> this really does not take much time, I'd like to have a cleaner way. Is
> there a simple way of creating a collection of only the VISIBLE worksheets
> in
> the ThisWorkbook - thus reducing the number of worksheets I need to
> iterate
> thru in the "For Each" loop??
>
> Taking it a step further....creating a collection of visible worksheets
> whose name matches the criteria I define??
>
> Thanks!!!



 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      26th Mar 2009
Can it be done... Absolutely. Should it be done... Probably not. Unless you
need to itterate through these sheets a whole pile of times or other
procedures need to use these same sheets then there will be more overhead in
creating the collection than there is in your existing code.
--
HTH...

Jim Thomlinson


"Rich" wrote:

> I need to search for data contained on certain worksheets. My current method
> is this:
>
> dim wks as worksheet
> For Each wks in ThisWorkbook.Worksheets
> if wks.name like "Data (*)" and wks.visible = xlSheetVisible
> ***now I collect my data***
> .....
>
> My question is....
> I have quite a few pages (15 to 18 min...maybe more) that are hidden, but I
> have to cycle thru them because they are part of "ThisWorkbook". Although
> this really does not take much time, I'd like to have a cleaner way. Is
> there a simple way of creating a collection of only the VISIBLE worksheets in
> the ThisWorkbook - thus reducing the number of worksheets I need to iterate
> thru in the "For Each" loop??
>
> Taking it a step further....creating a collection of visible worksheets
> whose name matches the criteria I define??
>
> Thanks!!!

 
Reply With Quote
 
Rich
Guest
Posts: n/a
 
      26th Mar 2009
Great! Thanks, guys!!
Being a bit of a rookie at this level of programming, I wanted to make sure
I was not taking the scenic path to the end result instead of the direct path.

Thanks for the replies!

"Jim Thomlinson" wrote:

> Can it be done... Absolutely. Should it be done... Probably not. Unless you
> need to itterate through these sheets a whole pile of times or other
> procedures need to use these same sheets then there will be more overhead in
> creating the collection than there is in your existing code.
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Rich" wrote:
>
> > I need to search for data contained on certain worksheets. My current method
> > is this:
> >
> > dim wks as worksheet
> > For Each wks in ThisWorkbook.Worksheets
> > if wks.name like "Data (*)" and wks.visible = xlSheetVisible
> > ***now I collect my data***
> > .....
> >
> > My question is....
> > I have quite a few pages (15 to 18 min...maybe more) that are hidden, but I
> > have to cycle thru them because they are part of "ThisWorkbook". Although
> > this really does not take much time, I'd like to have a cleaner way. Is
> > there a simple way of creating a collection of only the VISIBLE worksheets in
> > the ThisWorkbook - thus reducing the number of worksheets I need to iterate
> > thru in the "For Each" loop??
> >
> > Taking it a step further....creating a collection of visible worksheets
> > whose name matches the criteria I define??
> >
> > Thanks!!!

 
Reply With Quote
 
Rich
Guest
Posts: n/a
 
      26th Mar 2009
Thanks. I was just trying to make sure that I was doing this in the most
efficient way - for execution time, code writing and code organization.

"JLGWhiz" wrote:

> Your question is a little confusing, since the code you posted does
> eliminate the hidden sheets. It probably takes a gigasecond for the
> compiler to see that a sheet is not visible with the code currently used.
>
>
> "Rich" <(E-Mail Removed)> wrote in message
> news:1F3F1EFA-991B-4B08-BC15-(E-Mail Removed)...
> >I need to search for data contained on certain worksheets. My current
> >method
> > is this:
> >
> > dim wks as worksheet
> > For Each wks in ThisWorkbook.Worksheets
> > if wks.name like "Data (*)" and wks.visible = xlSheetVisible
> > ***now I collect my data***
> > .....
> >
> > My question is....
> > I have quite a few pages (15 to 18 min...maybe more) that are hidden, but
> > I
> > have to cycle thru them because they are part of "ThisWorkbook". Although
> > this really does not take much time, I'd like to have a cleaner way. Is
> > there a simple way of creating a collection of only the VISIBLE worksheets
> > in
> > the ThisWorkbook - thus reducing the number of worksheets I need to
> > iterate
> > thru in the "For Each" loop??
> >
> > Taking it a step further....creating a collection of visible worksheets
> > whose name matches the criteria I define??
> >
> > Thanks!!!

>
>
>

 
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
Re: How can I check a collection (e.g. worksheets) collection to beempty? Dave Peterson Microsoft Excel Programming 0 25th Mar 2010 02:15 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
Creating a new collection from an existing collection marcus.wade@smart-rs.com Microsoft VB .NET 5 8th Aug 2005 05:47 PM
Creating a new collection from an existing collection marcus.wade@smart-rs.com Microsoft VB .NET 2 3rd Aug 2005 12:43 PM
Worksheets are referenced in expressions, how make the worksheets visible? Excel 2000 L Mehl Microsoft Excel Misc 2 27th Jul 2004 07:20 PM


Features
 

Advertising
 

Newsgroups
 


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