I use the dictionary object from the MS Scripting Runtime library to save a series of arrays and perform operations on array cells as needed. There is a for loop to go through the process of creating all of these entries. My problem is that when using the .exists property .exists it returns True even before the item was added.
Close debugging indicates that the key is added to the dictionary at the beginning of the for loop, even if the .add command is not used and will not be used until the end of the loop.
I tried several different configurations, but here is a simple example that fails:
Dim dTotals As Dictionary Set dTotals = New Dictionary dTotals.CompareMode = BinaryCompare For Each cell In rAppID If Not dTotals.Exists(cell) Then Set rAppIDCells = Find_Range(cell, rAppID) Set rAppIDValues = rAppIDCells.Offset(0, 6) dAppIDTotal = WorksheetFunction.Sum(rAppIDValues) dTotals.Add Key:=cell.Value, Item:=dAppIDTotal End If Next cell
Where each cell contains a row / unique identifier. In the If statement, the code returns false, even at the first iteration.
source share