Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim t, BCM, n&, i&, deb!
deb = Timer
Application.ScreenUpdating = False
With Sheets("planning")
If Sh.Name = .Name Then Exit Sub
If .FilterMode Then .ShowAllData
t = .Range("a1").Resize(.Cells(.Rows.Count, "g").End(xlUp).Row, 9)
End With
i = 1: t(i, 2) = t(i, 3): t(i, 3) = t(i, 8): t(i, 4) = t(i, 9): BCM = Sh.Name: n = n + 1
For i = 2 To UBound(t)
If t(i, 1) = "" Then t(i, 1) = t(i - 1, 1)
If t(i, 7) = BCM Then n = n + 1: t(n, 1) = t(i, 1): t(n, 2) = t(i, 3): t(n, 3) = t(i, 8): t(n, 4) = t(i, 9)
Next i
With Sh
.Range(.Range("a2"), .Cells(.Rows.Count, 5)).ClearContents
.Range("a2").Resize(n, 4) = t
End With
MsgBox Format(Timer - deb, "0.000\ sec.")
End Sub