Option Explicit
Sub TEST5()
Dim ar, i&, j&, r&, dic As Object, strJoin$
If [G1].Value = "" Then MsgBox "查询月份为空!": Exit Sub
Set dic = CreateObject("Scripting.Dictionary")
ar = Sheets(1).[A1].CurrentRegion.Value
For i = 2 To UBound(ar)
strJoin = ar(i, 2) & Month(ar(i, 9)) & ar(i, 10)
dic(strJoin) = dic(strJoin) + ar(i, 8)
Next i
r = Cells(Rows.Count, "B").End(xlUp).Row
With Range("B4:F" & r)
.Offset(1, 1).ClearContents
ar = .Value
For i = 2 To UBound(ar)
For j = 2 To UBound(ar, 2) - 1
strJoin = ar(i, 1) & [G1].Value & ar(1, j)
ar(i, j) = dic(strJoin)
ar(i, UBound(ar, 2)) = ar(i, UBound(ar, 2)) + ar(i, j)
Next j
Next i
.Value = ar
End With
Set dic = Nothing
Beep
End Sub
|