|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
学习一下字典,打扰了
Sub test()
arr = Sheets("数据").[a1].CurrentRegion
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
If Not d.exists(arr(i, 1)) Then
Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
End If
d(arr(i, 1))(arr(i, 2)) = d(arr(i, 1))(arr(i, 2)) + 1
Next
brr = Sheets("统计").[a2].CurrentRegion
For i = 2 To UBound(brr)
For j = 2 To UBound(brr, 2)
If d.exists(brr(i, 1)) Then
If d(brr(i, 1)).exists(brr(1, j)) Then
brr(i, j) = d(brr(i, 1))(brr(1, j))
End If
End If
Next
Next
Sheets("统计").[a2].CurrentRegion = brr
End Sub |
评分
-
2
查看全部评分
-
|