|
对比测试代码运行时间:
Sub main()
tms = Timer
Set Dic = CreateObject("scripting.dictionary") '后期绑定字典
For i = 1 To 100 'Sheet1中有多少行,这里改为多少
Dic(Sheets(1).Cells(i, "A").Value) = Sheets(1).Cells(i, "B") 'Sheet1中名为字典目录,数值为字典项目
Next
For i = 1 To 200 'sheet2中最大行数
If Dic.exists(Cells(i, "A").Value) Then '如果字典中存在
Cells(i, "C") = Dic(Cells(i, "A").Value) '将字典中相应的值赋予C列中
End If
Next i
MsgBox Format(Timer - tms, "0.0000s")
End Sub
Sub test()
tms = Timer
Set d = CreateObject("scripting.dictionary")
arr = Sheet1.[a1].CurrentRegion
m = UBound(arr)
For i = 1 To m
d(arr(i, 1)) = arr(i, 2)
Next
brr = [a1].CurrentRegion
For i = 1 To UBound(brr)
If d.exists(brr(i, 1)) Then brr(i, 1) = d(arr(i, 1))
Next
[c1].Resize(m, 1) = brr
MsgBox Format(Timer - tms, "0.0000s")
End Sub |
评分
-
1
查看全部评分
-
|