Quick way of copying Range to (sub)Array ?

  • Thread starter Thread starter John Mitchell
  • Start date Start date
J

John Mitchell

dim a1(1 to 2, 1 to 3)
a1=range("a1:c3")

loads values from the selected range into the 2D array. Is there an
elegant way of doing the same sort of thing with a 2D subset of a 3D array?

dim a2(1 to 2, 1 to 3, 1 to 2)
a2(,,2)=range("a1:c3")

The left hand side of the last statement is syntactically incorrect but
hopefully serves to demonstrate what I am trying to achieve. I'd like to
avoid having to use a loop to load values into the array one element at
a time.

Regards, John M
 
Typo..

"a1:c3" should be "a1:c2". Apologies for any confusion. JM.
 
No, it doesn't. Either of the following does:

Dim a1 [or, in xl 2000 and later, Dim a1()]
a1 = Range("a1:c2")

or

Dim a1 [or, in xl 2000 and later, Dim a1()]
Redim a1(1 to 2, 1 to 3)
a1 = Range("a1:c2")

Some time back, Harlan Grove posted a function, aresize, that I believe
would do what you are asking, called, e.g.,

Dim a1
a1=Range("a1:c2")
aresize a1, 2, 3, 2

It doesn't do it without looping, of course, but the looping is
pre-packaged.

Alan Beban
 

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

Back
Top