R
Raul
I need to know if a multi-dimensional array can be populated directly from
non-contiguous ranges in a worksheet?
I can do the following but it gets pretty slow when the number of rows
exceeds 20000.
For i = 1 to 10000
NewArray(i,0) = Worksheets("All_Data").Cells(5 + i, 6)).Value
NewArray(i,1) = Worksheets("All_Data").Cells(5 + i, 12)).Value
NewArray(i,2) = Worksheets("All_Data").Cells(5 + i, 22)).Value
Next i
I can also populate one-dimensional arrays directly from a range and then
use a For Next Loop to populate NewArray(1 to 10000, 0 to 2)
DateArray =
Application.Transpose(ThisWorkbook.Sheets("All_Data").Range("F6:F10000"))
DataArray1 =
Application.Transpose(ThisWorkbook.Sheets("All_Data").Range("L6:L10000"))
DataArray2 =
Application.Transpose(ThisWorkbook.Sheets("All_Data").Range("V6:V10000"))
For i = 1 to 10000
NewArray(i,0) = DateArray(i)
NewArray(i,1) = DataArray1(i)
NewArray(i,2) = DataArray2(i)
Next i
But I’d like to be able to use something on the order of:
Application.Index(NewArray, 0, 1) =
Application.Transpose(ThisWorkbook.Sheets("All_Data").Range("L6:L1000"))
Or
Application.Index(NewArray, 0, 1) = DataArray1
Is this possible? If it is, can you give me an example?
Thanks in advance,
Raul
non-contiguous ranges in a worksheet?
I can do the following but it gets pretty slow when the number of rows
exceeds 20000.
For i = 1 to 10000
NewArray(i,0) = Worksheets("All_Data").Cells(5 + i, 6)).Value
NewArray(i,1) = Worksheets("All_Data").Cells(5 + i, 12)).Value
NewArray(i,2) = Worksheets("All_Data").Cells(5 + i, 22)).Value
Next i
I can also populate one-dimensional arrays directly from a range and then
use a For Next Loop to populate NewArray(1 to 10000, 0 to 2)
DateArray =
Application.Transpose(ThisWorkbook.Sheets("All_Data").Range("F6:F10000"))
DataArray1 =
Application.Transpose(ThisWorkbook.Sheets("All_Data").Range("L6:L10000"))
DataArray2 =
Application.Transpose(ThisWorkbook.Sheets("All_Data").Range("V6:V10000"))
For i = 1 to 10000
NewArray(i,0) = DateArray(i)
NewArray(i,1) = DataArray1(i)
NewArray(i,2) = DataArray2(i)
Next i
But I’d like to be able to use something on the order of:
Application.Index(NewArray, 0, 1) =
Application.Transpose(ThisWorkbook.Sheets("All_Data").Range("L6:L1000"))
Or
Application.Index(NewArray, 0, 1) = DataArray1
Is this possible? If it is, can you give me an example?
Thanks in advance,
Raul