View Single Post
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
Alan Beban Alan Beban is offline
external usenet poster
 
Posts: 200
Default A more elegant solution to grab a range?

You can also readily "destroy" the second dimension of a 2-D
*horizontal* array. The most commonly referred to way is

myArr = Application.Transpose(Application.Transpose(Range( "a1:z1").Value2))

Another is

myArr = Application.Index(Range("a1:z1").Value2, 1, 0)

Alan Beban

Charles wrote:
I am impressed. Very efficient!

thanks
Charles


Dave Peterson wrote:
Dim myArr As Variant
myArr = Application.Transpose(Range("a1:a100").Value2)

IIRC, this will break in some versions of excel if you have more than 5461
elements.

Charles wrote:
Hello

I am looking for a more elegant (and shorter) solution to grab the
content of an excel range into an array:

Dim grab
Dim value()
grab = Range("A1:A100").Value2
ReDim value(1 To UBound(grab))
For i = 1 To UBound(grab)
value(i) = grab(i, 1)
Next i

I could just use the array grab but then I have to carry a two
dimensional syntax all the way, although I know that grab only contains
one column. Or is there a simple instruction to "destroy " one of the
dimensions of an array?

Thanks ina advance
Charles

--

Dave Peterson