|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
学习一下字典,写得不好
Sub test()
arr = [a1].CurrentRegion
Set d = CreateObject("scripting.dictionary")
Set d1 = CreateObject("scripting.dictionary")
ReDim brr(1 To UBound(arr), 1 To 1000)
For i = 2 To UBound(arr)
If Not d.exists(arr(i, 2)) Then
c = c + 1
brr(1, c) = arr(i, 2)
brr(2, c) = arr(i, 1)
d(arr(i, 2)) = c
d1(arr(i, 2)) = 2
Else
d1(arr(i, 2)) = d1(arr(i, 2)) + 1
brr(d1(arr(i, 2)), d(arr(i, 2))) = arr(i, 1)
End If
Next
[e1].Resize(UBound(brr), d.Count) = brr
End Sub |
评分
-
1
查看全部评分
-
|