View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Keith R[_2_] Keith R[_2_] is offline
external usenet poster
 
Posts: 37
Default ReDim Preserve on 2D Array not working

"If you use the Preserve keyword, you can resize only the last array
dimension and you can't change the number of dimensions at all. For example,
if your array has only one dimension, you can resize that dimension because
it is the last and only dimension. However, if your array has two or more
dimensions, you can change the size of only the last dimension and still
preserve the contents of the array."

HTH,
Keith

"bony_tony" wrote in message
...
Hi,
I'm new to arrays.

I have attempted to create a 2D array for the following data in my
sheet. ("Joe" is in cell C3)

Name From To
Joe A E
Pritesh F Q
Richard R Z

I have the following, but after it tries to ReDim for the second time,
I get the error "Subscript out of range" I'm not sure what I'm doing
wrong.

Here's my code;

For i = 3 To Range("C65536").End(xlUp).Row
ReDim Preserve Split(1 To i - 2, 1 To 3)
Split(i - 2, 1) = Cells(i, 3)
Split(i - 2, 2) = Cells(i, 4)
Split(i - 2, 3) = Cells(i, 5)
Next i

Am I making an obvious mistake?

Cheers
Tony