Sub SousTotal()
Dim nlig&, i&, n&
Application.ScreenUpdating = False
ActiveSheet.UsedRange.Sort [A1], xlAscending, Header:=xlYes 'tri préalable
With [A1].CurrentRegion
nlig = .Rows.Count
For i = nlig To 2 Step -1
If .Cells(i, 1) <> .Cells(i - 1, 1) Then
.Rows(i).Insert xlDown
With .Rows(i)
.Clear 'efface les formats
.Cells(2, 9).Copy .Cells(9) 'copie le format en colonne I
.Interior.Color = 5287936 'vert
.Font.Bold = True 'gras
n = Application.CountIf(.Cells(1).EntireColumn, .Cells(2, 1))
If n = 0 Then n = nlig - i + 1
.Cells(9) = "=SUM(" & .Cells(2, 9).Resize(n).Address(0, 0) & ")"
.Cells(1) = .Cells(2, 1)
End With
End If
Next
End With
End Sub