Sub 汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long, rs As Long
Dim br(), cr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
ReDim br(1 To 100000, 1 To 9)
ReDim cr(1 To 100000, 1 To 9)
With Sheets("汇总")
ks = .[c3]
js = .[e3]
lh = 1
For Each sh In Sheets(Array("表1", "表2"))
m = m + 1
r = sh.Cells(Rows.Count, 2).End(xlUp).Row
ar = sh.Range("b5:j" & r)
For i = 2 To UBound(ar)
If ar(i, 2) <> "" Then
If IsDate(ar(i, 2)) Then
If ar(i, 2) >= ks And ar(i, 2) <= js Then
t = d(ar(i, 2))
If t = "" Then
k = k + 1
d(ar(i, 2)) = k
t = k
br(k, 1) = k
br(k, lh + m) = ar(i, 2)
If sh.Name = "表1" Then
br(k, 4) = ar(i, 3)
br(k, 5) = ar(i, 4)
br(k, 6) = ar(i, 5)
Else
br(k, 4) = ar(i, 4)
br(k, 5) = ar(i, 6)
br(k, 6) = ar(i, 8)
End If
End If
If sh.Name = "表1" Then
br(t, lh + m + 5) = br(t, lh + m + 5) + ar(i, 6)
Else
br(t, lh + m + 5) = br(t, lh + m + 5) + ar(i, 9)
End If
br(t, 9) = br(t, 9) + 1
Else
tt = d(ar(i, 2))
If tt = "" Then
kk = kk + 1
dc(ar(i, 2)) = kk
tt = kk
cr(kk, 1) = kk
cr(kk, lh + m) = ar(i, 2)
If sh.Name = "表1" Then
cr(kk, 4) = ar(i, 3)
cr(kk, 5) = ar(i, 4)
cr(kk, 6) = ar(i, 5)
Else
cr(kk, 4) = ar(i, 4)
cr(kk, 5) = ar(i, 6)
cr(kk, 6) = ar(i, 8)
End If
End If
If sh.Name = "表1" Then
cr(tt, lh + m + 5) = cr(tt, lh + m + 5) + ar(i, 6)
Else
cr(tt, lh + m + 5) = cr(tt, lh + m + 5) + ar(i, 9)
End If
cr(tt, 9) = cr(tt, 9) + 1
End If
End If
End If
Next i
d.RemoveAll
dc.RemoveAll
Next sh
.UsedRange.Offset(5) = Empty
.[b6].Resize(k, UBound(br, 2)) = br
.Cells(k + 7, 2).Resize(kk, UBound(cr, 2)) = cr
End With
MsgBox "ok!"
End Sub
|