Sub TriTablo()
'objectif avoir un tri comme suit:
'XX
'XX-1
'XX-2
'...
'XX-10
'XX-11
'YY
'...
'1 commencer par tout mettre sous la forme:
'XX-00 XX-01 XX-02 XX-10 YY-00
'2 trier
'3 remettre sous la forme initiale
Dim tablo() As Variant
With Sheets("Base de donnee")
Fin = .Range("A" & .Rows.Count).End(xlUp).Row
tablo = .Range("A3:J" & Fin).Value
For i = LBound(tablo, 1) To UBound(tablo, 1) 'on met la colonne A sous la forme XX-xx
On Error Resume Next
gauche = Split(tablo(i, 1), "-")(0)
droite = Split(tablo(i, 1), "-")(1)
If droite = "" Then droite = 0
tablo(i, 1) = Format(gauche, "00") & "-" & Format(droite, "00")
Next i
' With Sheets("Feuil1") 'on copie le résultat dans la feuille1
' .Range("A1").Resize(UBound(tablo, 1)) = tablo
' End With
'il faut maintenant trier sur la colonne A
indexColTri = 1 'colonne A
For i = LBound(tablo, 1) To UBound(tablo, 1)
For j = LBound(tablo, 1) To UBound(tablo, 1) - 1
'syntaxe pour le tri de données type Texte
If tablo(j, indexColTri) > tablo(j + 1, indexColTri) Then
For y = 1 To UBound(tablo, 2)
t = tablo(j, y)
tablo(j, y) = tablo(j + 1, y)
tablo(j + 1, y) = t
Next y
End If
Next j
Next i
' With Sheets("Feuil1") 'on copie le résultat dans la feuille1
' .Range("A1").Resize(UBound(tablo, 1), UBound(tablo, 2)) = tablo
' End With
'puis remettre sous la forme initiale
For i = LBound(tablo, 1) To UBound(tablo, 1) 'on met la colonne A sous la forme XX-xx
gauche = Split(tablo(i, 1), "-")(0)
droite = Split(tablo(i, 1), "-")(1)
If droite = "00" Then
tablo(i, 1) = Format(gauche, "0")
Else
tablo(i, 1) = format(gauche ,"0") & "-" & Format(droite, "0")
End If
Next i
With Sheets("Base de donnee") 'on copie le résultat dans la feuille1
.Range("A3").Resize(UBound(tablo, 1), UBound(tablo, 2)) = tablo
End With
End With
End Sub