Option Compare Text 'la casse est ignorée
Private Sub Worksheet_Change(ByVal Target As Range)
Dim t, ncol%, i&
With [A6:D999] 'plage à adapter, au moins 2 cellules
t = .Value
ncol = UBound(t, 2)
For i = 1 To UBound(t)
If t(i, 1) = "" Then t(i, 1) = "zzzzz"
If t(i, 1) Like "###-*" Then t(i, 1) = Mid(t(i, 1), 5)
Next
tri t, 1, UBound(t), ncol
For i = 1 To UBound(t)
If t(i, 1) <> "zzzzz" Then t(i, 1) = Format(i, "000-") & t(i, 1) Else t(i, 1) = ""
Next
Application.EnableEvents = False
.Value = t
Application.EnableEvents = True
End With
End Sub
Sub tri(a, gauc, droi, ncol) ' Quick sort
Dim ref, g, d, temp, col
ref = a((gauc + droi) \ 2, 1)
g = gauc: d = droi
Do
Do While a(g, 1) < ref: g = g + 1: Loop
Do While ref < a(d, 1): d = d - 1: Loop
If g <= d Then
For col = 1 To ncol
temp = a(g, col): a(g, col) = a(d, col): a(d, col) = temp
Next
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi, ncol)
If gauc < d Then Call tri(a, gauc, d, ncol)
End Sub