Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Not IsNumeric(Sh.Name) Then Exit Sub
Dim P As Range, c As Range, n&
Me.Names.Add "S", Sheets("EMP_PROP").Range("B" & Sh.Name).Resize(, 10)
Me.Names.Add "E", "EMPLACEMENTS" 'texte à adapter éventuellement
Me.Names.Add "T", "TOT" 'texte à adapter éventuellement
Application.ScreenUpdating = False
Sh.Cells.Delete 'RAZ
Set P = Sheets("EMP_WIN").UsedRange
If P.Rows.Count < 2 Then Exit Sub 'sécurité
'---filtre avancé---
Set c = P(2, P.Columns.Count + 1) 'cellule du critère
c = "=OR(COUNTIF(S,A2),A2=E,A2=T,A2=0)"
P.AdvancedFilter xlFilterInPlace, c(0).Resize(2)
With P.SpecialCells(xlCellTypeVisible).EntireRow
n = Intersect(.Cells, P.Columns(1)).Count
.Copy Sh.[A1]
End With
P.AdvancedFilter xlFilterInPlace, ""
c = ""
'---suppression des tableaux vides---
Set P = Sh.Cells(1, P.Columns.Count + 1).Resize(n) 'colonne auxiliaire
P.FormulaR1C1 = "=LN((RC1=E)*(R[2]C1=T)+(RC1=T)*IF(ROW()>1,OFFSET(RC1,-1,)=0)" & _
"+(RC1=0)*((R[1]C1=T)+IF(ROW()>3,OFFSET(RC1,-3,)=E)+IF(ROW()>4,OFFSET(RC1,-4,)=E)))"
On Error Resume Next 's'il n'y a rien à supprimer
P.SpecialCells(xlCellTypeFormulas, 1).EntireRow.Delete
P.Delete
End Sub