VBA 从数组创建字典
Function range2dict(keyarr, valarr) As Scripting.Dictionary
Dim mydict As Object
Dim i, key, val
Set mydict = CreateObject("scripting.dictionary")
For i = 1 To UBound(keyarr) - LBound(keyarr) + 1
key = keyarr(i)
val = valarr(i)
'Debug.Print key, val
If Not mydict.exists(key) Then
mydict.Add key, val
End If
Next
Set range2dict = mydict
End Function
经测试,第一条代码报错:用户定义类型未定义