|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
'理解起来挺费劲,不过速度快的还是不要不要的,哈哈哈
Option Explicit
Sub test()
Dim i, j, a, b, m, n, cnt, arr, sum, total
arr = Range("a2:c" & Cells(Rows.Count, "a").End(xlUp).Row + 1)
For i = 1 To UBound(arr, 1) - 1
For j = i To UBound(arr, 1) - 1
If arr(j, 1) <> arr(j + 1, 1) Then
total = 0: cnt = 0: n = 0
For a = i To j
sum = 0: n = 0
For b = a To j
n = n + 1
sum = sum + arr(b, 3)
If arr(b, 2) <> arr(b + 1, 2) Then
a = b: cnt = cnt + 1
total = total + sum / n: Exit For
End If
Next
Next
m = m + 1
arr(m, 1) = arr(i, 1): arr(m, 2) = cnt: arr(m, 3) = total / cnt
i = j: Exit For
End If
Next j, i
With [l2] '输出位置自己修改
.Resize(Rows.Count - 1, UBound(arr, 2)).ClearContents
If m > 0 Then .Resize(m, UBound(arr, 2)) = arr
End With
End Sub |
评分
-
1
查看全部评分
-
|