I've now got to the bottom of my issue. The solution was twofold. Firstly, when I first posted I thought that my code was storing my intended item as the key - I thought this because the 'watch' window showed the key in the value column. However, I've since learned that despite the misleading display, my items, i.e. the company names, were being stored correctly.
The second part of my problem was my incorrect use of the dictionary object functions and properties: I hadn't paid enough attention to how I was accessing items within the dictionary. I now use an array to store the items of the dictionaries, which pass these to other functions.
So, the final code to build the dictionaries is as follows:
Dim SICompanies As Scripting.Dictionary, SIZips As Scripting.Dictionary, _
WynCompanies As Scripting.Dictionary, WynZips As Scripting.Dictionary
Dim SIItems() As Variant, WynItems() As Variant, WynZipItems() As Variant, SIZipItems() As Variant
Dim contents As Variant
Dim cell As Range
contents = ws.Range("A2:D" & recCountALL).Value
Set SICompanies = New Scripting.Dictionary
Set SIZips = New Scripting.Dictionary
Set WynCompanies = New Scripting.Dictionary
Set WynZips = New Scripting.Dictionary
'loop through array
For i = 1 To UBound(contents, 1)
'if 1st column (Wyn ID) of array is not empty add to dictionary using wyn ID as key
If contents(i, 1) > 0 Then
WynCompanies.Add contents(i, 1), contents(i, 3)
WynZips.Add contents(i, 1), contents(i, 4)
Else 'if wyn ID is empty, must be SI record
SICompanies.Add contents(i, 2), contents(i, 3)
SIZips.Add contents(i, 2), contents(i, 4)
End If
Next i
WynItems = WynCompanies.Items
SIItems = SICompanies.Items
WynZipItems = WynZips.Items
SIZipItems = SIZips.Items
For i = 0 To UBound(SIItems)
maxDupeScore = 0
For j = 0 To UBound(WynItems)
' more code here
For Each cell In ws.Range("A1").CurrentRegion.Columns(3).Cells
If cell.Value = SIItems(i) Then
cell.Offset(0, 2).Value = maxDupeScore
Exit For
End If
Next cell
Next j
Next i
Hope this helps someone else...
Williams485
Bookmarks