I am trying to write worksheet data range from one place to other using array approach with a view to try array manipulation later. This program works fine.
Sub Array2Range5()
Dim Directory As Variant
Directory = Range("A30:D39").Value2
For i = LBound(Directory, 1) To UBound(Directory, 1)
For j = LBound(Directory, 2) To UBound(Directory, 2)
Worksheets("List").Range(Worksheets("List").Cells(i + 1, j + 1), Worksheets("List").Cells(i + 1, j + 1)) = Directory(i, j)
Next j
Next i
End Sub
The following program for same purpose gives run time error ‘9’.Subscript out of range in the following code portion.
Worksheets("List").Range(Worksheets("List").Cells(i + 1, j + 1), Worksheets("List").Cells(i + 1, j + 1)) = Directory(i, j)
I am not able to correct it and the program is as follows.
Sub Array2Range6()
Dim Directory As Variant
Directory = Range("A30:D39").Value2
For i = 0 To UBound(Directory, 1)
For j = 0 To UBound(Directory, 2)
Worksheets("List").Range(Worksheets("List").Cells(i + 1, j + 1), Worksheets("List").Cells(i + 1, j + 1)) = Directory(i, j)
Next j
Next i
End Sub
My query is whether these lines are wrong in syntax. If so what should be the correct syntax on similar lines
For i = 0 To UBound(Directory, 1)
For j = 0 To UBound(Directory, 2)
Any help shall be highly appreciated.