I have 3 dictionaries: one with the codes, the other one with currencies and S_Keys that should contain both values. The values are retrieved from the table in one of the worksheets. S_Keys dictionary doesn't work as expected and whenever I have the code value, it fails to find a matching value of a currency that corresponds to the code. How do I fix it?
Example:
Dic1: Codes
Dic2: Currencies
Dic 3: S_Keys: Codes: Currencies.
I know the mapping from the table attachedTable1. Let me know if you have any questions and thank you for your help!
Set W_Wbs = ActiveWorkbook
Set W_Curr = W_Wbs.Sheets("2a")
Set W_Property = W_Wbs.Sheets("2b")
For i = 1 To tblAttributes.DataBodyRange.Rows.Count
Dim propertyName As String
propertyName = tblAttributes.DataBodyRange.Cells(i, tblAttributes.ListColumns("Name").index).Value
Dim propertyCode As String
propertyCode = tblAttributes.DataBodyRange.Cells(i, tblAttributes.ListColumns("Code").index).Value
Dim baseCurrency As String
baseCurrency = tblAttributes.DataBodyRange.Cells(i, tblAttributes.ListColumns("Currency").index).Value
If Application.CountIf(wsPackage.Columns(4),Name) > 0 Then
S_Keys = Code & "¦" & Currency
If Not D_Dict.Exists("Currency") Then Set D_Dict("Currency") = CreateObject("Scripting.Dictionary")
If Not D_Dict.Exists("Keys") Then Set D_Dict("Keys") = CreateObject("Scripting.Dictionary")
If Not D_Dict.Exists("Name") Then Set D_Dict("Name") = CreateObject("Scripting.Dictionary")
If Not D_Dict("Code").Exists(Code) Then Set D_Dict("Code")(Code) = CreateObject("Scripting.Dictionary")
If Not D_Dict("Currency").Exists(Currency) Then Set D_Dict("Currency")(Currency) = CreateObject("Scripting.Dictionary")
If Not D_Dict("Keys").Exists(S_Keys) Then Set D_Dict("Keys")(S_Keys) = CreateObject("Scripting.Dictionary")
If Not D_Dict("Name").Exists(propertyName) Then Set D_Dict("Name")(Name) = CreateObject("Scripting.Dictionary")
End If
If Not dict.Exists(Name) Then
dict.Add Name, Array(Code, Currency)
Else
Dim existingValues As Variant
existingValues = dict(Name)
ReDim Preserve existingValues(0 To UBound(existingValues) + 2)
existingValues(UBound(existingValues) - 1) = Code
existingValues(UBound(existingValues)) = Currency
dict(Name) = existingValues
End If
Next i
Dim Codes As Variant