Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
series objects; finding specific ones in the collection | Charts and Charting in Excel | |||
Deleting named ranges by looping through range collection | Excel Programming | |||
Adding Range to Worksheet Names Collection | Excel Programming | |||
calculating and adding a range to a collection | Excel Programming | |||
Iterate over Collection Objects in Container. | Excel Programming |