Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default creating a collection of Sheets references

I want to treat all the sheets in a workbook, except for the first one, the
same way in various methods. So I wanted do something like:
Public NonControlWorksheetCollection As New Collection

Private Sub createNonControlWorksheetCollection()
' populate a collection of Sheets that doesn't include the Control Worksheet
' assumes the control worksheet is worksheet 1
Dim counter As Integer
Dim wks As Worksheet
Debug.Assert ThisWorkbook.Worksheets(1).Name = CONTROL_WKS_NAME
For counter = 2 To (ThisWorkbook.Worksheets.Count)
Set wks = ThisWorkbook.Worksheets(counter)
NonControlWorksheetCollection.Add (wks) <--------------------error:
method or property not supported
Next counter
End Sub

Since this didn't work, I did the below two methods, but it seems there
should be a more elegant solution.
TIA
-------------------------------------------------------------
Private Sub createNonControlWorksheetCollection()
' populate a collection of Sheets that doesn't include the Control Worksheet
' assumes the control worksheet is worksheet 1
Dim counter As Integer
Debug.Assert ThisWorkbook.Worksheets(1).Name = CONTROL_WKS_NAME
For counter = 2 To (ThisWorkbook.Worksheets.Count)
NonControlWorksheetCollection.Add (counter)
Next counter
End Sub

Public Function getWorksheet(index As Integer)
' To ease the burden of object creation in methods needing
nonControlWorksheets
' returns a Worksheet object for the passed index
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets(index)
End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default creating a collection of Sheets references

Eric,

Remove the parentheses from the following line of code in your
first procedu

NonControlWorksheetCollection.Add (wks)
<--------------------error:

When you include parens, Excel tries to evaluate the argument; in
this case it tries to retrieve the default property of the
worksheet object. Since the worksheet object has no default
property, you get an error.

In general, never use parens around arguments to Sub procedures
unless you know what you're doing.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Eric" wrote in message
nk.net...
I want to treat all the sheets in a workbook, except for the
first one, the same way in various methods. So I wanted do
something like:
Public NonControlWorksheetCollection As New Collection

Private Sub createNonControlWorksheetCollection()
' populate a collection of Sheets that doesn't include the
Control Worksheet
' assumes the control worksheet is worksheet 1
Dim counter As Integer
Dim wks As Worksheet
Debug.Assert ThisWorkbook.Worksheets(1).Name =
CONTROL_WKS_NAME
For counter = 2 To (ThisWorkbook.Worksheets.Count)
Set wks = ThisWorkbook.Worksheets(counter)
NonControlWorksheetCollection.Add (wks)
<--------------------error: method or property not supported
Next counter
End Sub

Since this didn't work, I did the below two methods, but it
seems there should be a more elegant solution.
TIA
-------------------------------------------------------------
Private Sub createNonControlWorksheetCollection()
' populate a collection of Sheets that doesn't include the
Control Worksheet
' assumes the control worksheet is worksheet 1
Dim counter As Integer
Debug.Assert ThisWorkbook.Worksheets(1).Name =
CONTROL_WKS_NAME
For counter = 2 To (ThisWorkbook.Worksheets.Count)
NonControlWorksheetCollection.Add (counter)
Next counter
End Sub

Public Function getWorksheet(index As Integer)
' To ease the burden of object creation in methods needing
nonControlWorksheets
' returns a Worksheet object for the passed index
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets(index)
End Function




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
creating cell references [email protected] Excel Discussion (Misc queries) 3 November 3rd 06 06:18 PM
collection of sheets mark Excel Programming 6 February 2nd 05 11:38 PM
Creating a formula that references other sheets WisconsinMike Excel Worksheet Functions 1 December 29th 04 05:50 PM
creating array using name references K[_3_] Excel Programming 0 October 8th 04 08:54 PM
How to find the type of Sheet in Excel.Workbook.sheets collection Raj[_7_] Excel Programming 3 December 9th 03 10:48 PM


All times are GMT +1. The time now is 09:02 AM.

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"