Option Explicit
Sub test()
Dim a, i As Long, j As Long, txt As String, n As Long
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Copie").Delete
Application.DisplayAlerts = True
Sheets("Exemple maco somme lots").Copy after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "Copie"
With Sheets("copie")
.Move before:=Sheets("Exemple maco somme lots")
With .Columns("a:d")
.MergeCells = False
End With
With .Range("a8", .Range("x" & Rows.Count).End(xlUp))
With .Offset(, 1).Resize(, 3)
.SpecialCells(4).Formula = "=r[-1]c"
.Value = .Value
End With
End With
On Error GoTo 0
With .Range("a6", .Range("x" & Rows.Count).End(xlUp))
a = .Value: n = 2
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 3 To UBound(a, 1)
txt = Join(Array(a(i, 2), a(i, 3), a(i, 4)), Chr(2))
If Not .exists(txt) Then
n = n + 1: .Item(txt) = n
For j = 1 To UBound(a, 2)
a(n, j) = a(i, j)
Next
Else
a(.Item(txt), 24) = a(.Item(txt), 24) + a(i, 24)
End If
Next
End With
End With
End With
'Restitution en Feuil1
With Sheets("Feuil1")
.Cells.Clear
With .Range("A1").Resize(n, UBound(a, 2))
.Value = a
.Columns.ColumnWidth = 1
.Columns.AutoFit
.Parent.Activate
End With
End With
Application.ScreenUpdating = True
End Sub