本帖最后由 zhangcheng6688 于 2024-6-3 16:35 编辑
学习一下字典,打扰了
Sub test()
arr = [b1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 3)
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
rq = Mid(arr(i, 3), 6, 2)
If Len([i2]) = 1 Then
s = "0" & [i2]
End If
If Len([j2]) = 1 Then
s1 = "0" & [j2]
End If
If rq >= s And rq <= s1 Then
If Not d.exists(arr(i, 1)) Then
m = m + 1
brr(m, 1) = arr(i, 1)
brr(m, 2) = 1
brr(m, 3) = arr(i, 2)
d(arr(i, 1)) = m
Else
r = d(arr(i, 1))
brr(r, 2) = brr(r, 2) + 1
brr(r, 3) = brr(r, 3) + Val(arr(i, 2))
End If
End If
Next
crr = [i2].CurrentRegion
For i = 3 To UBound(crr)
If d.exists(crr(i, 1)) Then
r1 = d(crr(i, 1))
crr(i, 2) = brr(r1, 2)
crr(i, 3) = brr(r1, 3)
Else
crr(i, 2) = 0
crr(i, 3) = 0
End If
Next
[i2].CurrentRegion = crr
End Sub
|