Sub SumUniqueItems()
Dim rngAnalysis As Range, arrAnalysis As Variant
Dim shtAnalysis As Worksheet, shtReport As Worksheet
Dim rngReport As Range
Dim lrowAnalysis As Long, i As Long, j As Long
Dim dictAnalysis As Object, dictKey As String
Dim dKey As Variant
Dim arrSplit As Variant
Dim arrOut() As Double
Dim TrimMeanPercent As Single
TrimMeanPercent = 0.2 ' <--- Note 20% takes 10% off the top and 10% off the bottom
Set shtAnalysis = Worksheets("analysis3") ' <--- Change to data source sheet name
With shtAnalysis.Range("C1").CurrentRegion
Set rngAnalysis = .Offset(1).Resize(.Rows.Count - 1)
End With
arrAnalysis = rngAnalysis.Value
Set shtReport = Worksheets("report3") ' <--- Change to output sheet name
Set rngReport = shtReport.Range("A2")
Set dictAnalysis = CreateObject("Scripting.dictionary")
' Load Analysis range into Dictionary & Concatenate the Values
For i = 1 To UBound(arrAnalysis) Step 1
For j = 1 To UBound(arrAnalysis, 2) Step 2
If arrAnalysis(i, j) <> "" Then
dictKey = arrAnalysis(i, j)
If Not dictAnalysis.exists(dictKey) Then
dictAnalysis(dictKey) = arrAnalysis(i, j + 1)
Else
dictAnalysis(dictKey) = dictAnalysis(dictKey) & "," & arrAnalysis(i, j + 1)
End If
End If
Next j
Next i
For Each dKey In dictAnalysis.keys
arrSplit = Split(dictAnalysis(dKey), ",")
ReDim arrOut(1 To UBound(arrSplit) + 1, 1 To 1)
For i = 0 To UBound(arrSplit)
arrOut(i + 1, 1) = arrSplit(i)
Next i
dictAnalysis(dKey) = Application.TrimMean(arrOut, TrimMeanPercent)
Next dKey
' Write back Totals
rngReport.CurrentRegion.Offset(1).ClearContents
rngReport.Resize(dictAnalysis.Count).Value = Application.Transpose(dictAnalysis.keys)
rngReport.Resize(dictAnalysis.Count).Offset(0, 1).Value = Application.Transpose(dictAnalysis.items)
End Sub