Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim Plage, Lig&
Application.ScreenUpdating = False
With Feuil1
If Sh.Name = .Name Then Exit Sub
Set Plage = .UsedRange
Sh.Cells.Clear
Plage.AutoFilter Field:=2, Criteria1:=Sh.Name
Plage.SpecialCells(xlCellTypeVisible).Copy Sh.[a1]
If .FilterMode Then .ShowAllData
End With
With Sh
Lig = .UsedRange.Rows.Count
.Cells(Lig + 1, "f") = "Totaux:": .Cells(Lig + 2, "f") = "Delta:"
.Range("f" & Lig + 1 & ":f" & Lig + 2).HorizontalAlignment = xlRight
.Cells(Lig + 1, "g") = Application.Sum(.Range("g2:g" & Lig))
.Cells(Lig + 1, "h") = Application.Sum(.Range("h2:h" & Lig))
On Error Resume Next
.Cells(Lig + 2, "g") = 0
.Cells(Lig + 2, "g") = (.Cells(Lig + 1, "g") - .Cells(Lig + 1, "h")) / .Cells(Lig + 1, "g")
.Cells(Lig + 2, "g").NumberFormat = "0.0%"
.Range("g" & Lig + 1 & ":h" & Lig + 1).NumberFormat = "# ##0.00"
End With
End Sub