Sub AddOrConcatRemoveDupli() ' Créé par RyuAutodidacte
Dim Sep$, Crit, Col, y As Byte, cLig As New Collection, C As Byte, L&, R&, VA, VR, x, DerL&
Sep = "|" ' Le séparateur
Crit = Array(1) ' Indiquer la ou les colonnes de critères
'-------------------------
Col = Array(2, 3, 4) 'Indiquer les colonnes concernées par les sommes ou les concaténations
Oper = Array("", "", "") 'Pour chaque colonne de Col concernée, mettre "" pour additionner ou mettre caractère de concaténation (ex. : "|" ou bien vbNewLine, etc…)
'-------------------------
VA = Sheets("IMPORT").Cells(1).CurrentRegion.Offset(1).Value
ReDim VR(1 To UBound(VA), 1 To UBound(VA, 2))
ReDim x(1 To UBound(VA))
For R = 1 To UBound(VA)
For i = LBound(Crit) To UBound(Crit): S = IIf(i = 0, VA(R, Crit(i)), S & Sep & VA(R, Crit(i))): Next
x(R) = S
On Error Resume Next
L = cLig(x(R))
On Error GoTo 0
If L Then
For y = LBound(Col) To UBound(Col)
If Oper(y) = "" Then
VR(L, Col(y)) = VR(L, Col(y)) + VA(R, Col(y))
Else
VR(L, Col(y)) = VR(L, Col(y)) & Oper(y) & VA(R, Col(y))
End If
Next
Else
L = cLig.Count + 1
cLig.Add L, CStr(x(R))
For C = 1 To UBound(VA, 2): VR(L, C) = VA(R, C): Next
End If
L = 0
Next
If cLig.Count < UBound(VR) Then
Application.ScreenUpdating = False
With Sheets("REGROUPEMENT")
DerL = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
.Range(.Cells(DerL, 1), .Cells(DerL, UBound(VA, 2))).Resize(cLig.Count).Value = VR
End With
Sheets("IMPORT").Rows(2 & ":" & UBound(VA)).Delete
Application.ScreenUpdating = True
End If
Set cLig = Nothing
End Sub