|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
学习一下字典,打扰了
Sub test()
arr = [a1].CurrentRegion
Set d = CreateObject("scripting.dictionary")
For i = 1 To UBound(arr, 2)
If Not d.exists(arr(1, i)) Then
Set d(arr(1, i)) = CreateObject("scripting.dictionary")
End If
For j = 2 To UBound(arr)
If Not d(arr(1, i)).exists(arr(j, i)) Then
d(arr(1, i))(arr(j, i)) = ""
End If
Next
Next
lastr = Cells(Rows.Count, "h").End(xlUp).Row
brr = Range("h5:i" & lastr)
For i = 1 To UBound(brr)
If d.exists(brr(i, 1)) Then
brr(i, 2) = d(brr(i, 1)).Count
Else
brr(i, 2) = "没有匹配数据"
End If
Next
[h5].Resize(UBound(brr), UBound(brr, 2)) = brr
End Sub |
|