AB33 I have gone and taken your code and think I learn more of the scripting dictionary. I wanted to try and create your program onto another sheet to do darn near the same thing. So I tweaked the column references inside the array to accommodate the different sheet.
This looks like it would work, the biggest difference in this list is that the list now might not contain the name from the main list. The code I have from you that is altered:
Sub GetRetainageAmt()
Dim x, i As Long, k As Long 'Declarations
With Worksheets("OnlyRetention")
x = .Range("J1:R" & .Range("J" & .Rows.Count).End(xlUp).Row)
End With
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 4 To UBound(x)
If Len(x(i, 1)) Then
If Not .exists(x(i, 1)) Then
ReDim Z(1 To 1)
Z(1) = x(i, 8)
.Item(x(i, 1)) = Z
Else
Z = .Item(x(i, 1))
Z(1) = Z(1) + x(i, 8)
.Item(x(i, 1)) = Z
End If
End If
Next i
With Worksheets("Main")
x = .Range("X1:Z" & .Range("X" & .Rows.Count).End(xlUp).Row)
End With
For i = 1 To UBound(x)
If Len(x(i, 2)) Then
If .exists(x(i, 2)) Then
k = k + 1
x(k, 2) = .Item(x(i, 2))(1)
End If
End If
Next
End With
With Worksheets("Main")
.Range("Z1:W" & .Rows.Count).ClearContents
If k > 0 Then .Range("Z1").Resize(k, 1) = x
End With
End Sub
Attached is a updated Test Excel File to view the new sheet that was added.
Bookmarks