|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
字典经典用法之一- Sub ykcbf() '//2024.11.29
- Set d = CreateObject("Scripting.Dictionary")
- r = Cells(Rows.Count, 1).End(3).Row
- arr = [a1].Resize(r, 2)
- ReDim brr(1 To r, 1 To 2)
- For i = 1 To UBound(arr)
- s = arr(i, 1)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = s
- End If
- s = arr(i, 1) & "-" & arr(i, 2)
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- brr(n, 2) = s
- End If
- Next
- Max = IIf(m < n, n, m)
- [d2].Resize(Max, 2) = brr
- Set d = Nothing
- MsgBox "OK!"
- End Sub
复制代码
|
|