我正在尝试将大小为183x6的2D数组分配给新工作表,使用数组的值填充A1:G182中的空白单元格.作为参考,我的数组称为"目录",我要填充的空表称为"列表".
我尝试了两种不同的方法,一种是通过显式地将指定的范围分配给数组:
Worksheets("List").Range(Cells(1,1), Cells(UBound(Directory, 1) + 1, UBound(Directory, 2) + 1)) = Directory
并且还尝试遍历数组中的每个条目:
For i = 0 To UBound(Directory, 1) For j = 0 To UBound(Directory, 2) Worksheets("List").Range(Cells(i + 1, j + 1), Cells(i + 1, j + 1)) = Directory(i,j) Next j Next i
在这两种情况下,我都会收到错误:
Run-time error '1004': Application-defined or object defined error.
有什么想法会发生什么?我感谢您的帮助.
尝试:
Worksheets("List").Range("A1").Resize(UBound(Directory, 1) + 1, UBound(Directory, 2) + 1).Value = Directory
要么:
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