|
Sub zz()
Dim d, arr, brr
Set d = CreateObject("Scripting.Dictionary")
arr = Sheet1.[a1].CurrentRegion
Sheet4.Range("A5").Resize(30, 27) = ""
brr = Sheet4.Range("A3").Resize(30, 27)
m = 3
For i = 2 To UBound(arr)
s = arr(i, 2)
If d(s) = "" Then
d(s) = m
brr(m, 1) = arr(i, 2)
For j = 4 To UBound(brr, 2)
If brr(1, j) <> "" And Month(arr(i, 1)) = brr(1, j) Then
brr(m, j) = arr(i, 3)
brr(m, j + 1) = arr(i, 5)
brr(m, 2) = arr(i, 3)
brr(m, 3) = arr(i, 5)
End If
Next
m = m + 1
Else
For j = 4 To UBound(brr, 2)
If brr(1, j) <> "" And Month(arr(i, 1)) = brr(1, j) Then
brr(d(s), j) = brr(d(s), j) + arr(i, 3)
brr(d(s), j + 1) = brr(d(s), j + 1) + arr(i, 5)
brr(d(s), 2) = brr(d(s), 2) + arr(i, 3)
brr(d(s), 3) = brr(d(s), 3) + arr(i, 5)
End If
Next
End If
Next
With Sheet4
.Range("A3").Resize(m, 27) = brr
.Range("A" & m + 2) = "合计"
.Range("B" & m + 2) = "=SUM(B5:B" & m + 1 & ")"
.Range("B" & m + 2).AutoFill Destination:=.Range("B" & m + 2 & ":" & "AA" & m + 2), Type:=xlFillDefault
End With
End Sub
|
|