Loop and name

J

JP

I assign values to range objects from an array. Is is possible to loop this?
My code is:

Set rng1 =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(1),
LookIn:=xlValues)

Set rng2 =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(2),
LookIn:=xlValues)

Set rng3 =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(3),
LookIn:=xlValues)

I can easily loop the array but how do you name the rng1, rng2 etc. ? They
are defined as Range. Thanks!
 
T

Tom Ogilvy

Make rng an array.

Dim rng(1 to 3) as Range
Set rng(1) =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(1),
LookIn:=xlValues)

Set rng(2) =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(2),
LookIn:=xlValues)

Set rng(3) =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(3),
LookIn:=xlValues)

for i = 1 to 3
msgbox rng(i).Address(0,0,xlA1,True)
Next
 
J

JP

Thanks! The thing is that I need the addresses to all rng:s. I use them like
this e.g.:

..SeriesCollection(1).XValues =
Sheets(varWorksheetInfoArray(0)).Range(rng1.Offset(i, 0).Address & ":" &
rng1.Offset(j, 0).Address)

is it possible to do the same when rng is defined as an array? Thank you
very much for your help!


"Tom Ogilvy" skrev:
 
T

Tom Ogilvy

..SeriesCollection(1).XValues =
Sheets(varWorksheetInfoArray(0)).Range(rng(1).Offset(i, 0).Address & ":" &
rng(1).Offset(j, 0).Address)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Looping Range 0
Type mixture error 2
Chart making 0
Syntax error.. 1
Checking contents of arrays 1
Update charts 0
Replace/substitute 0
Extract Text in braquet and list of terms from 2 Docs 3

Top