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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| Option Explicit
Option Base 0
Sub triMulticolonnes()
Dim Tableau()
Dim i As Integer, j As Integer, y As Integer, x As Integer
Dim indexColTri As Byte
Dim t As Variant
x = 50 'définit le nombre de lignes dans le tableau
'redimensionne le tableau (4 colonnes et x lignes)
ReDim Preserve Tableau(4, x)
'-----chargement d'un tableau à partir de valeurs aleatoires ------
For i = 0 To x - 1
Randomize
Tableau(0, i) = Chr(Int((26 * Rnd) + 1) + 64)
Randomize
Tableau(1, i) = Chr(Int((26 * Rnd) + 1) + 64)
Randomize
Tableau(2, i) = Chr(Int((26 * Rnd) + 1) + 64)
Randomize
Tableau(3, i) = Chr(Int((26 * Rnd) + 1) + 64)
Next i
'--------------------------------------------
'---- Appliquer un tri sur une des colonnes du tableau -----
'choisir la colonne à trier: 0=1ere colonne , 1=2eme colonne...etc ...
indexColTri = 0
For i = 0 To x - 1
For j = 0 To x - 2
'---------
'synthaxe pour tri données date
'If CDate(Tableau(indexColTri, j)) > _
CDate(Tableau(indexColTri, j + 1)) Then
'synthaxe pour tri données numériques
'If CDec(Tableau(indexColTri, j)) > _
CDec(Tableau(indexColTri, j + 1)) Then
'synthaxe pour tri données texte
If Tableau(indexColTri, j) > Tableau(indexColTri, j + 1) Then
'---------
For y = 0 To 3
t = Tableau(y, j)
Tableau(y, j) = Tableau(y, j + 1)
Tableau(y, j + 1) = t
Next y
End If
Next j
Next i
'------------------------------------------------------------
'---- afficher le resultat -----------------------------------
For i = 0 To x - 1
Debug.Print Tableau(0, i) & vbTab & Tableau(1, i) & vbTab & Tableau(2, i) & _
vbTab & Tableau(3, i)
Next i
'-------------------------------------------------------------
End Sub |
Partager