|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 zhangcheng6688 于 2024-10-12 07:40 编辑
学习一下字典
Sub test()
arr = [c13].CurrentRegion
Set d = CreateObject("scripting.dictionary")
ReDim brr(1 To UBound(arr), 1 To 4)
For i = 2 To UBound(arr)
If Not d.exists(arr(i, 3)) Then
Set d(arr(i, 3)) = CreateObject("scripting.dictionary")
End If
If Not d(arr(i, 3)).exists(arr(i, 2)) Then
m = m + 1
For j = 1 To 3
brr(m, j) = arr(i, j + 1)
Next
brr(m, 4) = arr(i, 1)
d(arr(i, 3))(arr(i, 2)) = m
Else
r = d(arr(i, 3))(arr(i, 2))
If brr(r, 1) < arr(i, 1) Then
For j = 1 To 3
brr(r, j) = arr(i, j + 1)
Next
brr(r, 4) = arr(i, 1)
End If
End If
Next
[h13].CurrentRegion.Offset(1).ClearContents
[h14].Resize(m, 4) = brr
End Sub
|
评分
-
1
查看全部评分
-
|