Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim P As Range, Q As Range, R As Range
Application.ScreenUpdating = False
With Sheets("BASE").[A1].CurrentRegion
Set P = .Columns(1).Resize(, 3) '3 premières colonnes
Set Q = .Rows(1).Find(Sh.Name, , xlValues, xlWhole) 'recherche de X ou Y
If Q Is Nothing Then Exit Sub
Set Q = Intersect(.Cells, Q.MergeArea.EntireColumn) 'colonnes X ou Y
Set R = Q.Columns(1).SpecialCells(xlCellTypeConstants).EntireRow 'filtrage
Sh.Cells.Delete 'EAZ
Intersect(Union(P, Q), R).Copy Sh.[A1] 'copier-coller
'---mises en forme---
With Sh.UsedRange
Set P = .Rows(2).Resize(Application.Max(.Rows.Count - 1, 2))
Sh.ListObjects.Add(xlSrcRange, P, , xlYes).Name = "Tableau" & Sh.Name 'création du tableau structuré
Set P = .Rows(3).Resize(.Rows.Count - 2)
Union(P.Columns(7), P.Columns(9), P.Columns(10)) = "" 'RAZ comme demandé
.Columns.AutoFit 'largeurs des colonnes
End With
End With
End Sub