Option Explicit
Sub Sous_total_insérer()
Dim c As Range, i As Long
With Application: .ScreenUpdating = False: .Calculation = xlManual: .EnableEvents = False: End With
On Error Resume Next
Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
With Range("a:d")
.RemoveSubtotal
.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(4), Replace:=True, SummaryBelowData:=True
.ClearOutline
End With
For Each c In Columns(4).SpecialCells(xlCellTypeFormulas, 23)
c(, -2).Resize(, 5).Interior.Color = 15395046
c(, -2).Resize(, 5).Font.Bold = True
Next
[E:E] = "" 'RAZ
[A1].CurrentRegion.Columns(5) = "=Pourcent()": [E1] = "%"
Columns.AutoFit
With Application: .EnableEvents = True: .Calculation = xlAutomatic: .ScreenUpdating = True: End With
End Sub
Function Pourcent()
Application.Volatile
Dim i&, j As Variant
Pourcent = ""
i = Application.Caller.Row
'If Cells(i, 1) Like "Total*" Then Exit Function 'si l'on ne veut pas des 100%
j = Application.Match("Total*", Range("A" & i & ":A" & Rows.Count), 0)
On Error Resume Next 'si le calcul n'est pas possible
Pourcent = Cells(i, 4) / Cells(i + j - 1, 4)
End Function