Sorry for the late reply I was very busy.
Try this
Sub Tester()
Dim rng As Range, dict As Object
With Sheets("Data").Activate
Set rng = Range(Range("A2"), Cells(Rows.Count, 1).End(xlUp)).Resize(, 3)
Set dict = SubTotals(rng, 1, 3)
DumpDict dict, Sheets("PT").Range("C4")
Sheets("PT").Activate
End With
End Sub
Function SubTotals(rng As Range, colKey As Long, colVal As Long) As Object
Dim rv As Object, rw As Range, k, v
Set rv = CreateObject("scripting.dictionary")
For Each rw In rng.Rows
k = rw.Cells(colKey).Value
v = rw.Cells(colVal).Value
If Not IsError(k) And Not IsError(v) Then
If Len(k) > 0 And IsNumeric(v) Then
rv(k) = rv(k) + v
End If
End If
Next rw
Set SubTotals = rv
End Function
Sub DumpDict(dict As Object, rng As Range)
Dim i As Long, k
i = 0
For Each k In dict.keys
With rng.Cells(1)
.Offset(i, 0).Value = k
.Offset(i, 1).Value = dict(k)
End With
i = i + 1
Next
End Sub
Bookmarks