vba - Dictionary object adding items before .add() is called -


itemprop = "text">

After I store a series of MS Scripting Runtime libraries using a array of objects Working on array cells as necessary and for loop through the process of making all these entries is one of my problems is that when using the .exists property, this object is returned This is returning to true before doing so.

Near debugging indicates that the key is being added to the dictionary at the beginning of the loop, even if no .add command is used and does not use it until the end will go . Loop

I've tried a few different configurations, but here is a simple example that fails:

  dTotals = new Set as dim dTotals Dictionary dTotals.CompareMode = BinaryCompare then set whether each cell in rAppID dTotals.Exists (cell) rAppIDCells = Find_Range (sales, rAppID) set rAppIDValues ​​= rAppIDCells.Offset (0, 6) dAppIDTotal = WorksheetFunction.Sum (rAppIDValues) dTotals.Add key = sales. Value, item: = DPIDtool and if the next cell   

, where each cell contains a string / unique ID, on the statement, the code is returning first, even on the first iteration.

In one? ??? For the scripting runtime it says, "If the key is not available when trying to return an existing item, a new key is created and its related object is left empty."

... and yes, again debugging in a loop, it appears that even before the '.exists' function pops out of the sky also appears. Everything's fine ...

Instead of trying to add the items that have been added now:

  dTotals.Add key: = cell.Value, Item: = DAppIDTotal   

... just set the empty object to its new one on its head:

  dTotals (cell.Value) = dAppIDTotal < / Code>  

then your code gets blocked:

  if not set dTotals.Exists (cell) then set rAppIDCells = Find_Range (cell, rAppID) rAppIDValues = RAppIDCells.Offset (0, 6) dAppIDTotal = WorksheetFunction.Sum (rAppIDValues) dTotals (cell.Value) = dAppIDTotal end then   

I search again each "VBA then again this" feature "on" Am I you intend to store what is happening with its effects can also see if you have new keys by adding a memory leak.

Comments