Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Range objects in a collection

Hello,

I've been trying to store a number of ranges in a collection, but
instead of storing the range it seems to store the cells value. The
purpose here is to add to the collection as needed and at the end
print out the contents with workbook, worksheet and cell reference for
each item.

Dim initRange as Range
Set initRange = worksheets("sheet1").Range("$A$1") ' contents = 48

Dim myCollection as New Collection
myCollection.Add(initRange)

Dim tempRange as Range
Set tempRange = myCollection.Item(1) 'fails with object required error

Any suggestions, or am I stuck using an array of ranges?

Thanks,
Corey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Range objects in a collection

On myCollection.Add(initRange), lose the ()'s. These are causing initRange
to be evaluated before the add.

Or add Call,

Call myCollection.Add(initRange), whch requires ()'s to enclose the
argument.

"Corey B" wrote in message
om...
Hello,

I've been trying to store a number of ranges in a collection, but
instead of storing the range it seems to store the cells value. The
purpose here is to add to the collection as needed and at the end
print out the contents with workbook, worksheet and cell reference for
each item.

Dim initRange as Range
Set initRange = worksheets("sheet1").Range("$A$1") ' contents = 48

Dim myCollection as New Collection
myCollection.Add(initRange)

Dim tempRange as Range
Set tempRange = myCollection.Item(1) 'fails with object required error

Any suggestions, or am I stuck using an array of ranges?

Thanks,
Corey



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Range objects in a collection

Remove the () from this line:
myCollection.Add(initRange)

And it worked ok for me.


Corey B wrote:

Hello,

I've been trying to store a number of ranges in a collection, but
instead of storing the range it seems to store the cells value. The
purpose here is to add to the collection as needed and at the end
print out the contents with workbook, worksheet and cell reference for
each item.

Dim initRange as Range
Set initRange = worksheets("sheet1").Range("$A$1") ' contents = 48

Dim myCollection as New Collection
myCollection.Add(initRange)

Dim tempRange as Range
Set tempRange = myCollection.Item(1) 'fails with object required error

Any suggestions, or am I stuck using an array of ranges?

Thanks,
Corey


--

Dave Peterson

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
series objects; finding specific ones in the collection cate Charts and Charting in Excel 2 April 4th 10 03:25 PM
Deleting named ranges by looping through range collection agarwaldvk[_11_] Excel Programming 3 August 3rd 04 01:00 AM
Adding Range to Worksheet Names Collection Keith Willshaw Excel Programming 2 March 5th 04 09:17 AM
calculating and adding a range to a collection marola20[_2_] Excel Programming 2 March 1st 04 03:24 PM
Iterate over Collection Objects in Container. Bob Kilmer Excel Programming 1 August 28th 03 02:37 AM


All times are GMT +1. The time now is 11:48 PM.

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

About Us

"It's about Microsoft Excel"