Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Custom Worksheet Collection

Is it possible to create a custom worksheet collection in VBA. That is I
normally loop thru worksheets as follows:

For Each wrksht In ActiveWorkbook

Next

But what if I want to loop thru certain sheets which I will define by items
in listboxes chosen by the user. I know I can create a collection and add
items to it but I am not sure how access that collection using the For Loop
above.

Does this mean I have to build a class module to create a custom worksheet
class?

Any ideas?

Thanks

EM




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Custom Worksheet Collection

On Jan 27, 7:12 pm, ExcelMonkey
wrote:
Is it possible to create a custom worksheet collection in VBA. That is I
normally loop thru worksheets as follows:

For Each wrksht In ActiveWorkbook

Next

But what if I want to loop thru certain sheets which I will define by items
in listboxes chosen by the user. I know I can create a collection and add
items to it but I am not sure how access that collection using the For Loop
above.

Does this mean I have to build a class module to create a custom worksheet
class?

Any ideas?

Thanks

EM


Hello Excel Monkey,

You don't need to create a Class Module for this. In this example, all
the code is in a Standard VBA Module. To make the collection available
throughout the project, the collection object variable is declared as
public. The LoadMyWorksheets macro puts the sheets you want into your
collection. You can then reference them using this format ...
MyWorksheets("sheet name")
This example loads 2 worksheets each from different workbooks.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Module Code
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Public MyWorksheets As Object

Sub LoadMyWorksheets()

Set MyWorksheets = New Collection

With MyWorksheets
.Add ThisWorkbook.Worksheets("Sheet1"), "Sheet1"
.Add Workbooks("Code For Lookup.xls").Worksheets("Sheet4"),
"Sheet4"
End With

End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Example
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub ReadData()

X = MyWorksheets("Sheet4").Range("A1").Value

End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sincerely,
Leith Ross
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
Collection custom functions as asn addin FARAZ QURESHI Excel Discussion (Misc queries) 2 December 29th 07 09:17 PM
E-mail Each WorkSheet in collection to pertaining Manager u473 Excel Programming 11 October 17th 07 04:09 PM
Delete worksheet in collection Stu W Excel Programming 4 June 26th 07 10:34 PM
How to check if a worksheet exists in worksheet collection Raghunandan Excel Programming 2 July 19th 04 06:55 AM
worksheet collection issue Mark Kubicki Excel Programming 2 November 18th 03 02:44 AM


All times are GMT +1. The time now is 01:19 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"