1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Option Explicit
Public Tbl()
Public Derlg As Range, Ws As Worksheet
Public Nb As Long, x As Long, y As Long, z As Integer
Sub Tri_tbl() 'procédure de tri ascendant
'Dim x As Integer
Dim Cible As String
For z = 1 To 2 'boucle qui reprendra 2 tris => 1 sur "Nature", 2 sur "Date"
Do 'voir l'aide "F1"
x = 0 'j'initialise la variable par sureté
For y = 1 To UBound(Tbl) - 1 'boucle sur les éléments de la variable tableau
If Tbl(y, z) > Tbl(y + 1, z) Then 'donc au début => si "reparation" est plus grand que "voiture"
'si oui
Cible = Tbl(y, 1) & ":" & Tbl(y, 2) & ":" & Tbl(y, 3) 'au début, cible = "reparation:01/03/2014:1000"
Tbl(y, 1) = Tbl(y + 1, 1): Tbl(y, 2) = Tbl(y + 1, 2): Tbl(y, 3) = Tbl(y + 1, 3) 'on affecte les valeurs des éléments suivants
'ci-dessous, et les éléments suivant sont réaffectés par les éléments précédents
Tbl(y + 1, 1) = Split(Cible, ":")(0)
Tbl(y + 1, 2) = Split(Cible, ":")(1)
Tbl(y + 1, 3) = Split(Cible, ":")(2)
x = 1
End If
Next y
Loop While x = 1
'ensuite on recommence pour le tri par date
Next z
End Sub |
Partager