|
楼主 |
发表于 2024-9-6 12:05
|
显示全部楼层
本帖最后由 djyang 于 2024-9-6 13:58 编辑
出错了请老师修改
Sub px()
Dim arr, d, d2, i&, zf$, n As Long
Set d = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
arr = Range("A1").CurrentRegion
For i = 2 To UBound(arr)
' 修改这里,从B列改为C列
Z = arr(i, 1) & "," & arr(i, 4) ' 第4列是C列
d2(Z) = d2(Z) + 1
s = (d2(Z) - 1) \ 6
zf = Z & "," & s
If Not d.exists(zf) Then
n = n + 1
d(zf) = n
arr(i, 2) = n ' 这里假设你仍然想在B列存储排序的结果(或任何其他逻辑)
Else
arr(i, 2) = d(zf)
End If
Next i
' 如果你希望将排序结果写回到C列,请改为Range("C1").Resize(UBound(arr, 1) - 1)
' 注意这里我使用了UBound(arr, 1) - 1因为CurrentRegion可能包括标题行
Range("C1").Resize(UBound(arr, 1) - 1).Value = Application.Index(arr, 1 To UBound(arr, 1), 2)
End Sub |
|