|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub test()
Dim arr, i, j, sum, m, n, max, pos
arr = Range("a2:g" & Cells(Rows.Count, "a").End(xlUp).Row + 1)
For i = 1 To UBound(arr, 1) - 1
sum = sum + arr(i, 3)
arr(i, 4) = 1000 * Month(arr(i, 1)) + arr(i, 2)
If arr(i, 2) <> arr(i + 1, 2) Then arr(i, 7) = sum: sum = 0
Next
pos = 1
For i = 1 To UBound(arr, 1) - 1
n = n + 1
arr(i, 5) = m + 1
If max < arr(i, 5) Then max = arr(i, 5)
If n Mod 6 = 0 Then m = m + 1
If arr(i, 4) <> arr(i + 1, 4) Then
For j = pos To i: arr(j, 6) = max: Next
pos = i + 1
n = 0: m = 0: max = 0
End If
Next
[j2].Resize(UBound(arr, 1) - 1, UBound(arr, 2)) = arr
End Sub |
|