I am trying to populate a 2D range with a 2D array.
At the moment I have this:
Sub populate()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
Dim Rows(2) As Variant
Rows(0) = [{1, 2, 3}]
Rows(1) = [{4, 5, 6}]
Rows(2) = [{7, 8, 9}]
With ws
.Range(.Cells(1, 1), .Cells(3, 3)).Value = Rows
End With
End Sub
I do not get any errors ect., but the range remains empty after running the macro.
The weirdest thing is that I get the correct output when I go like:
With ws
.Range(.Cells(1, 1), .Cells(3, 3)).Value = Application.Transpose(Application.transpose(Rows))
End With
I went through numerous articles and Microsoft Documents, but nothing came up to fix my problem.
Rows()is a 1-D array, whose elements are 1-D arrays. You need to get a genuine 2-D arrayDim Rows(2, 0) As VariantDim Rows() As Variant: Rows() = [{1, 2, 3; 4, 5, 6; 7, 8, 9}]Evaluatethen maybe try:Rows(0,0) = [Row(1:3)],Rows(1,0) = [Row(4:6)]andRows(2,0) = [Row(7:9)]. Is that what you are trying to do? Check the locale variables window to see what all different options do to your arrays.Rows(0, 0)(1, 1) = "Your value", this will change the value of the first element of the first 2D array in the first element of your 2D array =).......ehh, yes correct haha