1、先升序排序
2、试试以下代码
arr = Sheet1.[a1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 8)
brr(1, 1) = arr(2, 1)
brr(1, 3) = arr(2, 2)
min1 = 10 ^ 9
For i = 2 To UBound(arr) - 1
' If arr(i, 8) = arr(i + 1, 8) Then
'Debug.Print Month(arr(i, 1))
If Year(arr(i, 1)) = Year(arr(i + 1, 1)) Then
s = s + arr(i, 6)
s1 = s1 + arr(i, 7)
max1 = Application.Max(max1, arr(i, 3), arr(i + 1, 3))
min1 = Application.Min(min1, arr(i, 4), arr(i + 1, 4))
Else
n = n + 1
brr(n, 2) = arr(i, 1):
brr(n + 1, 1) = arr(i + 1, 1)
brr(n + 1, 3) = arr(i + 1, 2)
brr(n, 4) = Application.Max(max1, arr(i, 3))
brr(n, 5) = Application.Min(min1, arr(i, 4))
brr(n, 6) = arr(i, 5)
brr(n, 7) = s + arr(i, 6)
brr(n, 8) = s1 + arr(i, 7)
s = 0: s1 = 0: max1 = 0: min1 = 10 ^ 9
End If
Next
Sheet4.[A2].Resize(n + 1, 8) = ""
Sheet4.[A2].Resize(n, 8) = brr '
End Sub |