Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default An array of Cells?

Is there anyway to easily set up an array of cells, wherein each
element of the array would be a cells object? Do I need to set up a
class or is there something in Excel that already does this?

Im using Excel 2002.

-Abe

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default An array of Cells?


And by cells object, I meant range object.
-Abe

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default An array of Cells?

Here is an example that should get you started

Dim aryCells(1 To 5) As Object

Set aryCells(1) = Range("A1:A5")
Set aryCells(2) = Range("H1:H10")
'ETC

MsgBox Application.Sum(aryCells(1))

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ups.com...

And by cells object, I meant range object.
-Abe



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default An array of Cells?

Thanks Bob,

by the way, is there a way I can change the size of that object array?
(i.e. so I create an object called aryCells with indexes 1 thru 5, can
I later modify aryCells to have 15 range objects in it?)
-Abe

Bob Phillips wrote:
Here is an example that should get you started

Dim aryCells(1 To 5) As Object

Set aryCells(1) = Range("A1:A5")
Set aryCells(2) = Range("H1:H10")
'ETC

MsgBox Application.Sum(aryCells(1))

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ups.com...

And by cells object, I meant range object.
-Abe


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default An array of Cells?

Hi Abe,

you can. Just declare the array without dimensioning it in the first
place and do the initial dimensioning in a second step, like

Dim aryCells() As Range
ReDim aryCells(1 To 5)

Later on you then can resize the array using

ReDim Preserve aryCells(1 To 15)

where the keyword 'Preserve' prevents the array's actual content from
being deletet.

Regards
Ingolf



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default An array of Cells?

Sure

Dim aryCells

Redim aryCells(1 To 5)
Set aryCells(1) = Range("A1:A5")
Set aryCells(2) = Range("H1:H10")
'ETC

MsgBox aryCells(1).address

Redim Preserve aryCells(1 To 15)
set aryCells(12) = range("M1:M10")

MsgBox aryCells(12).address

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

wrote in message
oups.com...
Thanks Bob,

by the way, is there a way I can change the size of that object array?
(i.e. so I create an object called aryCells with indexes 1 thru 5, can
I later modify aryCells to have 15 range objects in it?)
-Abe

Bob Phillips wrote:
Here is an example that should get you started

Dim aryCells(1 To 5) As Object

Set aryCells(1) = Range("A1:A5")
Set aryCells(2) = Range("H1:H10")
'ETC

MsgBox Application.Sum(aryCells(1))

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ups.com...

And by cells object, I meant range object.
-Abe




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default An array of Cells?

Hi, Abraham

a simple array will do:

Sub RangeArray()
Dim rng(1 To 5) As Range
Dim i As Integer
For i = 1 To 5
Set rng(i) = Range("A1").Offset(i - 1, 0)
Next 'i
For i = 1 To 5
Debug.Print rng(i).Address
Next 'i
End Sub

Regards
Ingolf

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
Need help with cells Array Ayo Excel Discussion (Misc queries) 5 August 7th 08 09:02 PM
combining cells and array from different sheets into an array to pass to IRR() [email protected] Excel Discussion (Misc queries) 3 September 11th 06 07:17 AM
Array vs. Cells Robin Clay[_4_] Excel Programming 6 March 7th 06 11:10 PM
Can a UDF be used on an array of cells? Paul D. Simon Excel Worksheet Functions 3 September 8th 05 06:23 PM
How do I sum an array of cells, even if some of them are #N/A René Excel Discussion (Misc queries) 5 January 18th 05 02:28 PM


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