Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default excel arrays


I have an array - RangeArray = Array("Range1", "Range2","Range3") and I
define, elsewhere, Range1 as Worksheets(1).Range("A1:D5"), Range2 as
Worksheets(1).Range("J20:M35") etc...
I want to write the code such that myRange = RangeArray(m) where m is an
integer. Thus by choosing a value for m, I can define a particular
range. I've tried several ways but I am not having much luck. Can
anyone please help?
Regards, Ken Rock


*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default excel arrays

Ken,

This should get you started

Dim Range1 As Range
Dim Range2 As Range
Dim Range3 As Range
Dim RangeArray
Dim m As Long

Set Range1 = Worksheets(1).Range("A1:D5")
Set Range2 = Worksheets(1).Range("A11:D15")
Set Range3 = Worksheets(1).Range("A21:D25")
RangeArray = Array(Range1, Range2, Range3)
m = 1
MsgBox RangeArray(m).Address


--

HTH

RP
(remove nothere from the email address if mailing direct)


"kenrock" wrote in message
...

I have an array - RangeArray = Array("Range1", "Range2","Range3") and I
define, elsewhere, Range1 as Worksheets(1).Range("A1:D5"), Range2 as
Worksheets(1).Range("J20:M35") etc...
I want to write the code such that myRange = RangeArray(m) where m is an
integer. Thus by choosing a value for m, I can define a particular
range. I've tried several ways but I am not having much luck. Can
anyone please help?
Regards, Ken Rock


*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default excel arrays

How about:

Set myRange = range(RangeArray(m))

or if they're all on worksheets(1):

set myrange = worksheets(1).range(rangearray(m))




kenrock wrote:

I have an array - RangeArray = Array("Range1", "Range2","Range3") and I
define, elsewhere, Range1 as Worksheets(1).Range("A1:D5"), Range2 as
Worksheets(1).Range("J20:M35") etc...
I want to write the code such that myRange = RangeArray(m) where m is an
integer. Thus by choosing a value for m, I can define a particular
range. I've tried several ways but I am not having much luck. Can
anyone please help?
Regards, Ken Rock

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default excel arrays

May I add a small point?.
Baring in mind that we will be referring to Range2 when we use m=1 (cause
for three ranges m=0, 1, and 2)..:)
J_J

"Bob Phillips" wrote in message
...
Ken,

This should get you started

Dim Range1 As Range
Dim Range2 As Range
Dim Range3 As Range
Dim RangeArray
Dim m As Long

Set Range1 = Worksheets(1).Range("A1:D5")
Set Range2 = Worksheets(1).Range("A11:D15")
Set Range3 = Worksheets(1).Range("A21:D25")
RangeArray = Array(Range1, Range2, Range3)
m = 1
MsgBox RangeArray(m).Address


--

HTH

RP
(remove nothere from the email address if mailing direct)


"kenrock" wrote in message
...

I have an array - RangeArray = Array("Range1", "Range2","Range3") and I
define, elsewhere, Range1 as Worksheets(1).Range("A1:D5"), Range2 as
Worksheets(1).Range("J20:M35") etc...
I want to write the code such that myRange = RangeArray(m) where m is an
integer. Thus by choosing a value for m, I can define a particular
range. I've tried several ways but I am not having much luck. Can
anyone please help?
Regards, Ken Rock


*** Sent via Developersdex http://www.developersdex.com ***





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default excel arrays

Of course, it is well made :-))

Unfortunately, it is not absolute. Try it again, but add this line to the
start of the module and see what you get

Option Base 1

Bob


"J_J" wrote in message
...
May I add a small point?.
Baring in mind that we will be referring to Range2 when we use m=1 (cause
for three ranges m=0, 1, and 2)..:)
J_J

"Bob Phillips" wrote in message
...
Ken,

This should get you started

Dim Range1 As Range
Dim Range2 As Range
Dim Range3 As Range
Dim RangeArray
Dim m As Long

Set Range1 = Worksheets(1).Range("A1:D5")
Set Range2 = Worksheets(1).Range("A11:D15")
Set Range3 = Worksheets(1).Range("A21:D25")
RangeArray = Array(Range1, Range2, Range3)
m = 1
MsgBox RangeArray(m).Address


--

HTH

RP
(remove nothere from the email address if mailing direct)


"kenrock" wrote in message
...

I have an array - RangeArray = Array("Range1", "Range2","Range3") and

I
define, elsewhere, Range1 as Worksheets(1).Range("A1:D5"), Range2 as
Worksheets(1).Range("J20:M35") etc...
I want to write the code such that myRange = RangeArray(m) where m is

an
integer. Thus by choosing a value for m, I can define a particular
range. I've tried several ways but I am not having much luck. Can
anyone please help?
Regards, Ken Rock


*** Sent via Developersdex http://www.developersdex.com ***









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default excel arrays

kenrock wrote:
I have an array - RangeArray = Array("Range1", "Range2","Range3") and I
define, elsewhere, Range1 as Worksheets(1).Range("A1:D5"), Range2 as
Worksheets(1).Range("J20:M35") etc...
I want to write the code such that myRange = RangeArray(m) where m is an
integer. Thus by choosing a value for m, I can define a particular
range. I've tried several ways but I am not having much luck. Can
anyone please help?
Regards, Ken Rock


*** Sent via Developersdex http://www.developersdex.com ***

Gentlemen,
Many thanks for your prompt and knowledgeable responses to my query.
I now have the interesting task of trying out the solutions and at the
same time, improving my understanding of Excel spreadsheets.
Regards, Ken Rock
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default excel arrays

Yep!. Now I get Range1 as expected.
You are correct as before Bob.
Cheers
J_J

"Bob Phillips" wrote in message
...
Of course, it is well made :-))

Unfortunately, it is not absolute. Try it again, but add this line to the
start of the module and see what you get

Option Base 1

Bob


"J_J" wrote in message
...
May I add a small point?.
Baring in mind that we will be referring to Range2 when we use m=1 (cause
for three ranges m=0, 1, and 2)..:)
J_J

"Bob Phillips" wrote in message
...
Ken,

This should get you started

Dim Range1 As Range
Dim Range2 As Range
Dim Range3 As Range
Dim RangeArray
Dim m As Long

Set Range1 = Worksheets(1).Range("A1:D5")
Set Range2 = Worksheets(1).Range("A11:D15")
Set Range3 = Worksheets(1).Range("A21:D25")
RangeArray = Array(Range1, Range2, Range3)
m = 1
MsgBox RangeArray(m).Address


--

HTH

RP
(remove nothere from the email address if mailing direct)


"kenrock" wrote in message
...

I have an array - RangeArray = Array("Range1", "Range2","Range3") and

I
define, elsewhere, Range1 as Worksheets(1).Range("A1:D5"), Range2 as
Worksheets(1).Range("J20:M35") etc...
I want to write the code such that myRange = RangeArray(m) where m is

an
integer. Thus by choosing a value for m, I can define a particular
range. I've tried several ways but I am not having much luck. Can
anyone please help?
Regards, Ken Rock


*** Sent via Developersdex http://www.developersdex.com ***








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
Elements and Arrays in Excel Lighthouseman Excel Worksheet Functions 6 February 1st 06 10:06 AM
arrays in excel Dan Excel Worksheet Functions 9 May 24th 05 07:01 PM
Arrays in Excel VBA Eliezer Excel Programming 4 September 3rd 04 08:37 PM
arrays on forms in Excel Bob Phillips[_6_] Excel Programming 0 June 29th 04 06:33 PM
arrays on forms in Excel Chip Pearson Excel Programming 0 June 29th 04 05:19 PM


All times are GMT +1. The time now is 08:15 AM.

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"