I want to populate a range of cells with the elements of an array.
The only method I know is limited to populating cells along one row, for example:
Sub testArrayOne()
Dim arrHeader As Variant
arrHeader = Array("1", "", "2", "", "3")
Sheets(2).range("A1:A5").Value = arrHeader
End Sub
But I'm wondering how to populate a range that has multiple rows, or only the dimensions of one column. My confusion stems from my lack of understanding of how arrays work in general and in VBA.
With this code I was expecting that cell A1 would have the value 1, and cell C3 the value 9.
Sub testArrayTwo()
Dim arrHeader As Variant
arrHeader = Array("1", "2", "3", "4", _
"5", "6", "7", "8", "9")
Sheets(2).range("A1:C3").Value = arrHeader
End Sub
Instead this is what I got:
I can see that only the first three values were used to populate the first row, and this process was repeated for the rest of the rows, but I don't know why that happens and what I must do to get the desired output.
Edit: as reference, the solution (adapted from here):
Sub testArrayThree()
Dim arrHeader As Variant
arrHeader = [{1, 2, 3; 4, 5, 6; 7, 8, 9}]
Sheets(2).Range("A1:C3").Value = arrHeader
End Sub