|
代码如下:
Sub test()
Application.ScreenUpdating = False
Set d = CreateObject("scripting.dictionary")
For Each sht In Sheets([{"今年","前年"}])
With sht
n = 0
r = .UsedRange.Rows.Count
arr = .Range("a3:i" & r)
ReDim brr(1 To UBound(arr), 1 To 2)
For i = 1 To UBound(arr)
If arr(i, 1) = Sheets("客户单月数据").[c3] Then
m = Month(CDate(arr(i, 2)))
s = arr(i, 1) & "|" & m
If Not d.exists(s) Then
n = n + 1
d(s) = n
brr(n, 1) = m
brr(n, 2) = arr(i, 8)
Else
x = d(s)
brr(x, 2) = brr(x, 2) + arr(i, 8)
End If
End If
Next
With Sheets("客户单月数据")
If sht.Name = "今年" Then
Set Rng = .Range("b6:c17")
Else
Set Rng = .Range("b6:c17").Offset(, 3)
End If
Rng.Offset(, 1).ClearContents
For i = 1 To n
Rng.Cells(brr(i, 1), 2) = brr(i, 2)
Next
End With
d.RemoveAll
End With
Next
Beep
Application.ScreenUpdating = True
End Sub |
|