Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
With Sh
If .CodeName <> "Feuil1" Or Intersect(Target, .[A:E]) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
If .FilterMode Then .ShowAllData 'RAZ
.PageSetup.PrintArea = .Range("A2:E" & .Range("A" & Rows.Count).End(xlUp).Row).Address 'zone d'impression
If .[A1] = "Tout" Or .[A1] = "" Then Exit Sub
.[G3] = "=A3=--A$1" 'critère de filtrage
.Range(.PageSetup.PrintArea).AdvancedFilter xlFilterInPlace, .[G2:G3] 'filtre avancé
.[G3] = ""
End With
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Workbook_SheetChange ActiveSheet, [A1] 'au cas où la zone d'impression a été effacée
End Sub