|
Sub 汇总()
Dim fpath As String, d, i As Integer, arr, brr, str As String
Dim wk As Workbook
Dim n As Byte, m As Integer, ii As Integer
arr = Application.GetOpenFilename(, 2, , , True)
If IsArray(arr) = False Then Exit Sub
Set d = CreateObject("scripting.dictionary")
For n = 1 To UBound(arr)
Set wk = Workbooks.Open(arr(1))
brr = Range("a1").CurrentRegion
i = Cells(Rows.Count, 1).End(3).Row
ii = UBound(brr, 2)
For m = 3 To i
For ii = 3 To UBound(brr, 2)
str = Cells(m, 2).Text & "," & Cells(2, ii).Text
d(str) = d(str) + Cells(m, ii).Value
Next ii
Next m
Erase brr
wk.Close
Set wk = Nothing
Next n
brr = Range("a1").CurrentRegion
i = Cells(Rows.Count, 1).End(3).Row
ii = UBound(brr, 2)
For m = 3 To i
For ii = 3 To UBound(brr, 2)
str = Cells(m, 2).Text & "," & Cells(2, ii).Text
Cells(m, ii) = d(str)
Next ii
Next m
Set d = Nothing
End Sub
|
|