Re: Merge duplicate rows and sum value
On the basis that your data starts "A2", has a max of 7 columns and you want the result based on the first 4 columns, Try this:-
NB:- This code will alter your data.
Code
Sub DelDupAdd()
Dim Rng As Range, Dn As Range, n As Long, Dic As Object, Txt As String, nRng As Range
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
Set Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
For Each Dn In Rng
With Application
Txt = Join(.Transpose(.Transpose(Dn.Resize(, 4))), ",")
End With
If Not Dic.Exists(Txt) Then
Dic.Add Txt, Dn
Else
Dic(Txt).Offset(, 4).Value = Dic(Txt).Offset(, 4).Value + Dn.Offset(, 4).Value
If nRng Is Nothing Then Set nRng = Dn Else Set nRng = Union(nRng, Dn)
End If
Next
If Not nRng Is Nothing Then nRng.EntireRow.Delete
End Sub
Display More
Regards Mick