|
Sub 按月汇总()
Dim ar As Variant
Dim i As Long, r As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With ActiveSheet
r = .Cells(Rows.Count, 3).End(xlUp).Row
ar = .Range("c1:d" & r)
ReDim br(1 To UBound(ar), 1 To 2)
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
If IsDate(ar(i, 1)) Then
yf = Format(ar(i, 1), "yyyy/m")
t = d(yf)
If t = "" Then
k = k + 1
d(yf) = k
t = k
br(k, 1) = yf
End If
br(t, 2) = br(t, 2) + ar(i, 2)
End If
End If
Next i
rs = .Cells(Rows.Count, 9).End(xlUp).Row
If rs > 1 Then .Range("i2:j" & rs) = Empty
.[i2].Resize(k, 2) = br
End With
MsgBox "ok!"
End Sub
|
|