When I do the code shown below, the array automatically re-dimensions itself to Z(1 to 10)
and I do not like how it re-dimensions because I always want to keep the array positions the same as its row positions in the spreadsheet. But I will still be able to assign the array to the excel range by equating both to each other as shown below:
Dim range_test As Range
Set range_test = ThisWorkbook.Worksheets("Sheet1").Range("A2:A11")
ReDim Z(2 To 11) As Variant
Z = range_test
ThisWorkbook.Worksheets("Sheet1").Range("D2:D11") = Z
But when I include the entire range (including the first row or the header, then my issue is that I cannot use the code I used above to assign the array to the excel range else it will include the header. So I will have to do it the way shown below:
Dim range_test As Range
Set range_test = ThisWorkbook.Worksheets("Sheet1").Range("A1:A11")
ReDim Z(1 To 11) As Variant
Z = range_test
Dim i As Long
For i = 2 To 11
ThisWorkbook.Worksheets("Sheet1").Range("E" & i) = Z(i, 1)
Next i
What I want to do is something similar to the logic where the arrays allow you to slice it similarly to other languages such as MATLAB because I feel creating a loop for populating an array is more resource heavy compared to equating an array to a range and vice versa (please correct me if i'm wrong). Please refer to the conceptualization below:
ThisWorkbook.Worksheets("Sheet1").Range("G2:G11") = Z(2 to 11)
ThisWorkbook.Worksheets("Sheet1").Range("H2:H11") = Y(2 to 11)