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

 

转载于:https://www.cnblogs.com/scai/p/10955355.html

你可能感兴趣的:(vba通过字典方式进行查询,速度快)