Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If UBound(Split(Sh.Name, " à ")) <> 1 Then Exit Sub
Dim F As Worksheet, n&, colaux1 As Range, colaux2 As Range, r As Range, a
Application.ScreenUpdating = False
Sh.Rows("2:" & Sh.Rows.Count).Delete 'RAZ
Set F = Sheets("Source " & Right(Sh.Name, 4)) 'feuille source
n = Month("1 " & Split(Sh.Name, " à ")(0)) '1er mois du trimestre
Set colaux1 = F.UsedRange.Columns(F.UsedRange.Columns.Count + 1).Cells
colaux1(1) = 1: colaux1.DataSeries 'numérotation des lignes
F.UsedRange.Sort F.[R1], xlAscending 'tri ascendant sur les dates
Set colaux2 = colaux1.Offset(, 1)
colaux2.FormulaR1C1 = "=LN(AND(RC18<>"""",MONTH(RC18)>=" & n & ",MONTH(RC18)<" & n + 3 & "))"
If Application.CountIf(colaux2, 0) Then
Set r = colaux2.SpecialCells(xlCellTypeFormulas, 1) 'cellules filtrées
'---copie des colonnes (S pour le format) ---
a = Array("D", "A", "J", "K", "C", "R", "S") 'colonnes sources
For n = 0 To UBound(a)
Intersect(r.EntireRow, F.Columns(a(n))).Copy Sh.Cells(2, n + 2)
Next
Intersect(r.EntireRow, F.[AH:AH]).Copy Sh.[L2]
Intersect(r.EntireRow, F.[G:G]).Copy Sh.[M2]
'---remplissage de la colonne H---
colaux2.FormulaR1C1 = "=SUM(RC19:RC30)"
colaux2 = colaux2.Value
r.Copy colaux2(1, 2)
Sh.Cells(2, "H").Resize(r.Count) = colaux2(1, 2).Resize(r.Count).Value
End If
colaux2.Resize(, 2).EntireColumn.Delete
F.UsedRange.Sort colaux1 'rétablit l'ordre initial
colaux1.EntireColumn.Delete
End Sub