Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "Tri" Then
Application.ScreenUpdating = False
Sheets("BDD").[A:M].Copy Sh.[A1]
Sh.[A:M].Sort Sh.[A1], xlAscending, Sh.[B1], , xlAscending, Header:=xlYes 'tri sur 2 colonnes
Sh.Range("H2:H" & Sh.Rows.Count).ClearContents 'supprime les formules des temps
ElseIf Sh.Name = "Résultat" Then
Dim F As Worksheet, col%
Set F = Sheets("Tri")
Workbook_SheetActivate F 'lance la macro
Sh.Cells.Delete 'RAZ
F.[N2] = "=(G2=1)*(OFFSET(G2,-1,)<>1)+(G2=0)*(""""&OFFSET(G2,1,)<>""0"")" 'critère pour supprimer les doublons
F.[A:M].AdvancedFilter xlFilterCopy, F.[N1:N2], Sh.[A1] 'filtre avancé
F.[N2] = ""
Intersect(Sh.Range("H2:H" & Sh.Rows.Count), Sh.UsedRange.EntireRow) = "=IF(""""&G2=""0"",A2+B2-A1-B1,"""")" 'formules des temps
For col = 1 To 12: Sh.Columns(col).ColumnWidth = F.Columns(col).ColumnWidth: Next 'largeurs des colonnes
End If
End Sub