Private Sub Worksheet_Activate()
Dim tablo, resu(), i&, n&
With Sheets("Base") 'nom de la feuille à adapter
If .FilterMode Then .ShowAllData 'si la feuille est filtrée
With .[A1].CurrentRegion
.Sort .Cells(1), xlAscending, Header:=xlYes 'tri préalable
tablo = .Resize(, 9) 'matrice, plus rapide
End With
End With
ReDim resu(1 To UBound(tablo), 1 To 3) '3 colonnes
For i = 2 To UBound(tablo)
If tablo(i, 9) <> "" Or tablo(i, 1) <> tablo(i - 1, 1) Then
n = n + 1
resu(n, 1) = tablo(i, 1)
End If
resu(n, 2) = resu(n, 2) + Val(Replace(tablo(i, 3), ",", "."))
resu(n, 3) = resu(n, 3) + Val(Replace(tablo(i, 4), ",", "."))
Next
'---restitution---
If FilterMode Then ShowAllData 'si la feuille est filtrée
With [A2] '1ère cellule de restitution, à adapter
If n Then .Resize(n, 3) = resu
.Offset(n).Resize(Rows.Count - n - .Row + 1, 3).ClearContents 'RAZ en dessous
End With
With UsedRange: End With 'actualise la barre de défilement verticale
End Sub