Sub TRI()
Dim Tablo As Range, N° As Range, Voyage As Range, Heure As Range, t, ub&, numero(), i&, n&, p&, Auxiliaire As Range
'---à adapter éventuellement---
Set Tablo = Sheets("bd").[A:F]
Set N° = Tablo.Columns(1)
Set Voyage = Tablo.Columns(5)
Set Heure = Tablo.Columns(6)
Application.ScreenUpdating = False
On Error Resume Next 'si aucune SpecialCell
'---tris---
Tablo.Sort Voyage, xlAscending, N°, , xlAscending, Header:=xlYes
Intersect(Tablo, Voyage.SpecialCells(xlCellTypeBlanks).EntireRow).Sort Heure, xlAscending, N°, , xlAscending, Header:=xlNo
'---numérotation des lignes en colonne auxiliaire G---
With Tablo.CurrentRegion
Intersect(.Offset(1), Voyage.SpecialCells(xlCellTypeConstants, 2).EntireRow).Cut 'coupe les lignes des textes en colonne E
If Application.CutCopyMode Then .Rows(2).Insert 'insère les lignes des textes au début du tableau
t = Voyage.Resize(.Rows.Count, 2) 'matrice plus rapide, au moins 2 éléments
ub = UBound(t)
ReDim numero(1 To Rows.Count, 1 To 1)
numero(2, 1) = 0
For i = 3 To ub
If t(i, 1) <> t(i - 1, 1) Then 'ajoute 2 lignes au tableau numero
n = n + 1: p = p + 1: numero(ub + p, 1) = n
n = n + 1: p = p + 1: numero(ub + p, 1) = n
End If
n = n + 1
numero(i, 1) = n
Next
Set Auxiliaire = Tablo.Columns(Tablo.Columns.Count + 1).Resize(ub + p)
Auxiliaire = numero 'restitution
.Resize(ub + p, Auxiliaire.Column).Sort Auxiliaire, xlAscending, Header:=xlYes 'tri final sur G
End With
'---bordures---
Tablo.Borders.LineStyle = xlNone 'RAZ
With Tablo.CurrentRegion.Resize(, Auxiliaire.Column - 1)
.Borders.Weight = xlThin
For i = 7 To 10: .Borders(i).Weight = xlMedium: Next
Auxiliaire.Resize(ub + p).ClearContents 'efface la colonne auxiliaire G
.Offset(.Rows.Count).Resize(Rows.Count - .Rows.Count).Delete xlUp 'nettoyage sous le tableau
End With
With Tablo.Parent.UsedRange: End With 'actualise les barres de défilement
End Sub