如何在Excel VBA中使用字典Dictionary对象
2015-08-02 · 知道合伙人软件行家
关注
展开全部
我把我自己学习的代码复制给你看看。字典功能最大的好处是运算速度快,比数组快10倍以上。
Sub test()
Dim dic As Object, arr
Dim tt
tt = Timer
Set dic = CreateObject("scripting.dictionary")
arr = Range("A2:B10000")
For i = 1 To UBound(arr, 1)
dic(arr(i, 1)) = dic(arr(i, 1)) + arr(i, 2)
Next i
[C1] = "姓名"
[D1] = "底薪"
[C2].Resize(dic.Count, 1) = Application.WorksheetFunction.Transpose(dic.keys)
[D2].Resize(dic.Count, 1) = Application.WorksheetFunction.Transpose(dic.Items)
tt = Timer - tt
[g1] = tt
End Sub
Sub test()
Dim dic As Object, arr
Dim tt
tt = Timer
Set dic = CreateObject("scripting.dictionary")
arr = Range("A2:B10000")
For i = 1 To UBound(arr, 1)
dic(arr(i, 1)) = dic(arr(i, 1)) + arr(i, 2)
Next i
[C1] = "姓名"
[D1] = "底薪"
[C2].Resize(dic.Count, 1) = Application.WorksheetFunction.Transpose(dic.keys)
[D2].Resize(dic.Count, 1) = Application.WorksheetFunction.Transpose(dic.Items)
tt = Timer - tt
[g1] = tt
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |