|
楼主 |
发表于 2016-5-20 16:46
|
显示全部楼层
你好,请教一下以下问题:现想将工作簿中多个表的内容一一赋给数组再合并,执行出错,需要怎么修改?
Sub hbewsz() '将工作簿中多个表的内容一一赋给数组再合并
Dim n%, i%, arr, arr1 '此处后两个为Variant 数据类型变量
n = ActiveWorkbook.Worksheets.Count
For i = 1 To n
arr = Sheets(i).[a1].CurrentRegion
arr1 = xhfz(arr)
Erase arr
Next
ActiveWorkbook.Worksheets.add after:=Worksheets(n)
ActiveSheet.Range("a1").Resize(UBound(arr1), UBound(arr1, 2)) = arr1
End Sub
Function xhfz(arr)
Dim i&, j&, k&
ReDim Preserve arr1(1 To 300000, 1 To UBound(arr, 2))
For i = 1 To UBound(arr)
k = k + 1
For j = 1 To UBound(arr, 2)
arr1(k, j) = arr(i, j)
Next j
Next i
xhfz = arr1
End Function |
|