Sub test()
Dim I As Long, Lig As Long, LigDeb As Long
'on désactive l'affichage. Permet une execution plus rapide de la macro
Application.ScreenUpdating = False
'pour chaque ligne "I" de la colonne A en partant de la dernière jusqu'à la 2
For I = [A65536].End(xlUp).Row To 2 Step -1
'si la ligne du dessous est différente de la ligne actuelle on insert une ligne
If Range("A" & I + 1).Value <> Range("A" & I).Value Then Rows(I + 1).Insert
Next
Lig = 2
'la boucle ci-dessous va ajouter les sous-totaux
Do
Lig = Range("A" & Lig).End(xlDown).Row
'"LigDeb" compte le nombre d'id pour la "zone en cours"
LigDeb = Application.CountIf(Range("A2", Range("A" & Lig)), Range("A" & Lig).Value)
'ici on écrit la fonction somme en colonne I
Range("I" & Lig + 1).FormulaLocal = "=SOMME(I" & Lig - LigDeb + 1 & ":I" & Lig & ")"
'"TOTAL" en colonne B
Range("B" & Lig + 1).Value = "TOTAL:"
'et le N° id en colonne A
Range("A" & Lig + 1).Value = "id" & Range("A" & Lig).Value
'on insert 2 lignes avant et après le total
Rows(Lig + 2).Insert: Rows(Lig + 1).Insert
'colore la ligne total en rouge
Rows(Lig + 2).Interior.Color = vbRed
Lig = Lig + 4
Loop Until Lig - 2 = [A65536].End(xlUp).Row
Application.ScreenUpdating = True
End Sub