|
Sub 汇总统计()
Dim i, j, k, irow1, m, n, kk, item
Dim arr, teparr, crr
Dim sht As Worksheet
Dim a As Date
a = Time
Dim d1 As Object
Dim d2 As Object
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("统计表").Range("h1:j100").Clear
Sheets("统计表").Cells(1, 8) = "日期"
Sheets("统计表").Cells(1, 9) = "A支出"
Sheets("统计表").Cells(1, 10) = "B支出"
ReDim arr(1 To 500, 1 To 4)
For Each sht In Worksheets
If sht.Name <> "统计表" Then
j = j + 1
teparr = sht.[a1].CurrentRegion
irow1 = sht.[a65536].End(xlUp).Row
For n = 2 To irow1
For m = 1 To 2
arr(n - 1, m + 2 * j - 2) = teparr(n, m)
Next
Next
End If
Next
For k = 1 To UBound(arr)
If arr(k, 1) <> "" Then
d1(arr(k, 1)) = d1(arr(k, 1)) + arr(k, 2)
End If
If arr(k, 3) <> "" Then
d2(arr(k, 3)) = d2(arr(k, 3)) + arr(k, 4)
End If
Next
ReDim crr(1 To d1.Count + d2.Count, 1 To 2)
For Each kk In d2.keys
If Not d1.exists(kk) Then
d1(kk) = "" & "," & d2(kk)
Else
d1(kk) = d1(kk) & "," & d2(kk)
End If
Next
ReDim crr(1 To d1.Count, 1 To 2)
For Each item In d1.items
i = i + 1
If InStr(item, ",") >= 1 Then
crr(i, 1) = Split(item, ",")(0)
crr(i, 2) = Split(item, ",")(1)
Else
crr(i, 1) = item
crr(i, 2) = ""
End If
Next
With Sheets("统计表")
.[h2].Resize(d1.Count, 1) = Application.WorksheetFunction.Transpose(d1.keys)
.[i2].Resize(UBound(crr), UBound(crr, 2)) = crr
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "ok"
MsgBox Time - a
End Sub |
|