PC Review


Reply
Thread Tools Rate Thread

Array of Range Objects

 
 
ExcelMonkey
Guest
Posts: n/a
 
      9th Jun 2008
Is it possible to create an array of range objects? I have used the Set stmt
for range objects (Example #1). Is it possible to set up many rang objects
in an array and use the Set stmt on this array(Example #2)? If so how would
you dimension the array?

Example #1
Set rng = ........

Example#2
For X = 0 to 10
Set RngArray(0) = .....
Next
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      9th Jun 2008
You could set up your array to hold variants which will allow for ranges but
a collection is generally a little easier when you want to store a group of
objects. Something like this...

Sub test()
Dim colRanges As Collection
Dim rng

Set colRanges = New Collection
With colRanges
.Add Range("A1:A10")
.Add Range("B1:B10")
.Add Range("C1:C10")
End With

For Each rng In colRanges
MsgBox rng.Address
Next rng
End Sub
--
HTH...

Jim Thomlinson


"ExcelMonkey" wrote:

> Is it possible to create an array of range objects? I have used the Set stmt
> for range objects (Example #1). Is it possible to set up many rang objects
> in an array and use the Set stmt on this array(Example #2)? If so how would
> you dimension the array?
>
> Example #1
> Set rng = ........
>
> Example#2
> For X = 0 to 10
> Set RngArray(0) = .....
> Next

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      9th Jun 2008
Yes, it is possible; but, as Jim said, a collection is easier to use. Here
are two examples showing you the answer to your question...

Sub DynamicRangeArray()
Dim Rng() As Range
ReDim Rng(1 To 3)
Set Rng(1) = Cells(1, 2)
Set Rng(2) = Range("D4:F20")
Set Rng(3) = Columns("G:G")
MsgBox Rng(1).Address & vbLf & Rng(2).Address & vbLf & Rng(3).Address
End Sub

Sub FixedRangeArray()
Dim Rng(1 To 3)
Set Rng(1) = Cells(1, 2)
Set Rng(2) = Range("D4:F20")
Set Rng(3) = Columns("G:G")
MsgBox Rng(1).Address & vbLf & Rng(2).Address & vbLf & Rng(3).Address
End Sub

Rick

"ExcelMonkey" <(E-Mail Removed)> wrote in message
news:457D1EB3-4659-46E1-8469-(E-Mail Removed)...
> Is it possible to create an array of range objects? I have used the Set
> stmt
> for range objects (Example #1). Is it possible to set up many rang
> objects
> in an array and use the Set stmt on this array(Example #2)? If so how
> would
> you dimension the array?
>
> Example #1
> Set rng = ........
>
> Example#2
> For X = 0 to 10
> Set RngArray(0) = .....
> Next


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
Problem instantiating an array of objects or array of class instances raylopez99 Microsoft C# .NET 3 17th Sep 2007 07:16 PM
copying an arraylist of objects into an array of the objects themselves. hazz Microsoft C# .NET 5 18th Nov 2005 04:19 PM
Easy way to cast an array of strings to an array of objects? ssg31415926 Microsoft C# .NET 3 30th Aug 2005 08:39 PM
Is an array of Objects in vb.net a good equivalent for an array of Variants in v WayneM Microsoft VB .NET 4 21st Nov 2003 10:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:37 PM.