判断字典key存在与否,用exists方法。
仍然以下面的数据为测试。
源数据
Sub a()
Dim arr, d As Object
Set d = CreateObject("scripting.dictionary")
arr = [a1].CurrentRegion
'----------新增字典d的条目-----------------------
For i = 2 To UBound(arr)
d(arr(i, 1)) = arr(i, 2)
Next
If d.exists("金砖") Then
MsgBox "存在金砖这个key"
Else
MsgBox "不存在金砖这个key"
End If
End Sub