vba通过字典方式进行查询,速度快

Sub 字典()
t=timer
Dim arr, brr, crr, d, i&
Sheets("目标表").Activate
Set d = CreateObject("scripting.dictionary")
arr = Sheets("源数据").Range("a1").CurrentRegion
brr = Range("a1").CurrentRegion
ReDim crr(1 To UBound(brr) - 1, 1 To 1)
For i = 2 To UBound(arr)
    d(arr(i, 1)) = arr(i, 2)
Next
For i = 2 To UBound(brr)
    crr(i - 1, 1) = d(brr(i, 1))
Next
Range("b2").Resize(UBound(crr)) = crr
MsgBox "一共用时:" & Format(Timer - t, "#0.0000") & "", , "友情提示!!"  '//提示
End Sub

 

posted on 2019-05-31 15:11  这个名字不好用  阅读(2236)  评论(0编辑  收藏  举报

导航