Option Explicit
Option Compare Text 'la casse n'a pas d'importance
Sub Tri()
Dim derlig&, plage As Range, i&, t, d As Object
derlig = [B3].End(xlDown).Row
If derlig = Rows.Count Then Exit Sub
Application.ScreenUpdating = False
Set plage = Range("A3:I" & derlig)
'---tableau préparatoire trié---
Range("A" & derlig + 1 & ":I" & Rows.Count).Delete xlUp 'RAZ
plage.Copy Cells(derlig + 1, 1)
Set plage = plage.Offset(plage.Rows.Count)
For i = 2 To plage.Rows.Count 'pour la 2ème clé de tri
t = Trim(plage.Cells(i, 8))
If t = "rouge" Then plage.Cells(i, 9) = 1
If t = "orange" Then plage.Cells(i, 9) = 2
If t = "jaune" Then plage.Cells(i, 9) = 3
If t = "" Then plage.Cells(i, 9) = 4
Next
plage.Sort [B1], xlAscending, [I1], , xlAscending, [G1], xlAscending, xlYes
plage.Columns(9).ClearContents
'---liste des titres des tableaux---
Set d = CreateObject("Scripting.Dictionary")
For i = 2 To plage.Rows.Count
d(plage.Cells(i, 2).Value) = plage.Cells(i, 2).Value
Next
'---création des tableaux---
ActiveSheet.AutoFilterMode = False
For Each t In d.keys
derlig = Cells(Rows.Count, 2).End(xlUp).Row
Cells(derlig + 3, 2) = t
Cells(derlig + 3, 2).Borders.LineStyle = 1 'bordures
plage.AutoFilter 2, t 'filtre automatique
plage.SpecialCells(xlCellTypeVisible).Copy Cells(derlig + 5, 1)
plage.AutoFilter
Next
ActiveSheet.AutoFilterMode = False
plage.Delete xlUp
End Sub