'2,多工作簿汇总(Consolidate)
'多工作簿汇总
Sub ConsolidateWorkbook()
Dim RangeArray() AsString
Dim bk As Workbook
Dim Sht As Worksheet
Dim WbCount As Integer
WbCount =Workbooks.Count
ReDim RangeArray(1 ToWbCount - 1)
For Each bk In Workbooks'在所有工作簿中循环
If Not bk Is ThisWorkbook Then '非代码所在工作簿
Set Sht = bk.Worksheets(1) '引用工作簿的第一个工作表
i = i + 1
RangeArray(i) = "'[" & bk.Name & "]" & Sht.Name& "'!" & _
Sht.Range("A1").CurrentRegion.Address(ReferenceStyle:=xlR1C1)
End If
Next
Worksheets(1).Range("A1").Consolidate RangeArray, xlSum, True, True
End Sub
联系客服