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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| Sub triMulticolonnes()
Dim Tableau()
Dim i As Integer, j As Integer, y As Integer
Dim x As Integer, w As Integer
Dim indexColTri As Byte
Dim t As Variant
w = 2 'Nombre total de colonnes dans le tableau
'Nombre de lignes dans le tableau
x = Range("A65536").End(xlUp).Row
Tableau = Range(Cells(1, 1), Cells(x, w))
'---- Applique un tri sur une des colonnes du tableau -----
indexColTri = 1 'Spécifie la colonne à trier
For i = 1 To x
For j = 1 To x - 1
'---------
'synthaxe pour tri données date:
'If CDate(Tableau(j, indexColTri)) > CDate(Tableau(j + 1, indexColTri)) Then
'synthaxe pour tri données numériques:
If CDec(Tableau(j, indexColTri)) > CDec(Tableau(j + 1, indexColTri)) Then
'synthaxe pour tri données texte:
'If Tableau(j, indexColTri) > Tableau(j + 1, indexColTri) Then
'---------
For y = 1 To w
t = Tableau(j, y)
Tableau(j, y) = Tableau(j + 1, y)
Tableau(j + 1, y) = t
Next y
End If
Next j
Next i
'------------------------------------------------------------
'---- affiche le resultat ---
Range(Cells(1, 1), Cells(x, w)) = Tableau
'-----------------------------
End Sub |
Partager