Private Sub Worksheet_Change(ByVal Target As Range)
Dim d As Object, dd As Object, tablo, resu(), i&, x$, y$, n&, nn&, z$, p%, q%, v&
Set d = CreateObject("Scripting.Dictionary")
d.CompareMode = vbTextCompare 'la casse est ignorée
Set dd = CreateObject("Scripting.Dictionary")
dd.CompareMode = vbTextCompare 'la casse est ignorée
tablo = [A1].CurrentRegion.Resize(, 3) 'matrice, plus rapide
ReDim resu(1 To UBound(tablo), 1 To 3)
For i = 2 To UBound(tablo)
x = tablo(i, 1): y = x & tablo(i, 2)
If Not d.exists(x) Then
n = n + 1
d(x) = n 'mémorise la ligne
resu(n, 1) = tablo(i, 1)
End If
nn = d(x)
resu(nn, 3) = resu(nn, 3) + tablo(i, 3)
If Not dd.exists(y) Then
dd(y) = ""
z = resu(nn, 2)
resu(nn, 2) = IIf(z = "", "", z & " - ") & tablo(i, 2) & "()"
End If
y = tablo(i, 2) & "("
z = resu(nn, 2)
p = InStr(z, y) + Len(y)
q = InStr(p, z, ")")
v = Val(Mid(z, p)) + tablo(i, 3) 'somme des valeurs entre parenthèses
resu(nn, 2) = Left(z, p - 1) & v & Mid(z, q)
Next
'---restitution---
Application.EnableEvents = False 'désactive les évènements
If FilterMode Then ShowAllData 'si la feuille est filtrée
With [H2] '1ère cellule de destination
If n Then .Resize(n, 3) = resu
.Offset(n).Resize(Rows.Count - n - .Row + 1, 3).ClearContents 'RAZ en dessous
End With
Application.EnableEvents = True 'réactive les évènements
End Sub