0
我想用字典做查找。但是,我无法提取密钥的offset
。Excel VBA +查找与词典
我检查过我的字典已经加载了我想要的所有数据,包括必要的offset
值。 (为评论的下一个循环)
我现在的问题是,如何找到Dic.Exists(profitCentre)
找到offset
值?
Dim cl As Range, Dic As Object
Set Dic = CreateObject("Scripting.Dictionary"): Dic.Comparemode = vbTextCompare
With Workbooks(wbPropListing).Sheets("Residential")
For Each cl In .Range("E3:E" & .Cells(Rows.Count, "E").End(xlUp).row)
If Not Dic.Exists(cl.Value) Then Dic.Add cl.Value, cl.Offset(, 1).Value
Next cl
End With
With Workbooks(wbPropListing).Sheets("Fund&CoT")
For Each cl In .Range("E2:E" & .Cells(Rows.Count, "E").End(xlUp).row)
If Not Dic.Exists(cl.Value) Then Dic.Add cl.Value, cl.Offset(, 1).Value
Next cl
End With
'For i = 0 To Dic.Count - 1
' Debug.Print Dic.items()(i), Dic.keys()(i)
'Next i
i = 0
For Each profitCentre In myProfitCentreArray
If profitCentre <> "" And Not profitCentre Like "####0000" And Dic.Exists(profitCentre) Then
lookupFound = Dic.items()
End If
Debug.Print "Index: " & i & " profit centre: " & profitCentre & " Lookup: " & lookupFound
i = i + 1
Next profitCentre
'lookupFound = DIC(profitCentre)' –