不要使用對象作為KEY,應該使用簡單類型,判斷存在的方法是Exists,最好使用賦值語句代替.Add,可以避免重復導致的問題。修改後的代碼:
Option?Explicit
Sub?dic()
Dim?d,?i%,?j%,?temp
Dim?k,?v
Set?d?=?CreateObject("Scripting.Dictionary")
For?i?=?1?To?Sheet1.[a66].End(3).Row
k?=?Trim(Sheet1.Cells(i,?1))
v?=?Sheet1.Cells(i,?2).Value
d(k)?=?v
Next?i
For?j?=?1?To?Sheet2.[a66].End(3).Row
k?=?Trim(Sheet2.Cells(j,?1))
If?d.Exists(k)?Then
Sheet2.Cells(j,?2).Value?=?d(k)
End?If
Next
End?Sub