I am using a dictionary object from the MS Scripting Runtime library to store a series of arrays and perform operations on the array cells as necessary. There is a for loop to go through the process of creating all of these entries. My issue is that when using the .exists property, it is returning a True even before the item has been added. Closer debugging indicates that the key is being added to the dictionary at the beginning of the for loop, even though no .add command is used and will not be used until the end of the loop. The result is that the values in the arrays do not totalize as intended.
Code for the dictionary build has been included below. I have attached the Excel file which contains the appropriate module which calls that function
Option Explicit[ATTACH]46705[/ATTACH] Function DictAppTable(Loop_Range As Integer, Key_Range As Range, Dim_1 As Range, Dim_2 As Range) Dim DictTable As Dictionary Dim AppElement(0 To 0, 0 To 1) As Variant Dim iD As Integer Dim strAppID As String Dim strAppIDnum As String Dim ProtoElement As Variant Dim intSize As Integer Dim iK As Integer Dim MtrElement(0 To 0, 0 To 1) As Variant Set DictTable = New Dictionary DictTable.RemoveAll DictTable.CompareMode = TextCompare For iD = 1 To Loop_Range strAppID = Key_Range.Rows(iD).Value strAppIDnum = Right(strAppID, 5) AppElement(0, 0) = strAppID AppElement(0, 1) = Dim_2.Rows(iD).Value MtrElement(0, 0) = Dim_1.Rows(iD).Value MtrElement(0, 1) = Dim_2.Rows(iD).Value If DictTable.Exists(strAppID) Then DictTable(strAppID)(0, 1) = MtrElement(0, 1) + DictTable(strAppID)(0, 1) DictTable(strAppID) = CombineTwoDArrays(DictTable(strAppID), MtrElement) Else ProtoElement = CombineTwoDArrays(AppElement, MtrElement) DictTable.Add Key:=strAppID, Item:=ProtoElement End If Debug.Print DictTable(strAppID)(0, 0) Debug.Print DictTable(strAppID)(0, 1) Debug.Print DictTable(strAppID)(1, 0) Debug.Print DictTable(strAppID)(1, 1) Next iD arKey = DictTable.Keys
My apologies for the previous post, as the pared down excel file which I posted had a slight error which prevented it from running