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
| 'Option Explicit
Sub tri_tableau_par_index_00() ' demande Patricktoulon
Dim a As Integer, i As Integer, N As Integer
Dim mavar As Integer, Var As Integer, maplage As Range
Dim montab As Variant
Dim tablo2 ' tableau provisoire
Dim tablo3() ' montab trie
' récupération des valeurs dans le tableau
' 7,3,2,6,5,1,4,8
' 45,37,49,21,85,49,51,24
montab = Range("B21:I22").Value
' tableau provisoire
tablo2 = Array(45, 37, 49, 21, 85, 49, 51, 24)
' ou
'tablo2 = Array(Range("B22"), Range("C22"), Range("D22"), Range("E22"), Range("F22"), Range("G22"), Range("H22"), Range("I22"))
' ou .....
N = UBound(tablo2)
ReDim Preserve tablo3(2, N)
For i = 0 To N
' ces 2 lignes sont pour vérifier ces 2 variables en pas à pas
mavar = Application.WorksheetFunction.Large(tablo2, i + 1)
Var = Application.Match(Application.WorksheetFunction.Large(tablo2, i + 1), tablo2, 0) - 1
tablo3(0, N - a) = montab(1, Var + 1)
tablo3(1, N - a) = montab(2, Var + 1)
tablo2(Var) = mavar + 1
a = a + 1
Next
' pour vérifier le résultat
' 6 8 3 7 1 2 4 5
' 21 24 37 45 49 49 51 85
Set maplage = Range("B25:I26")
maplage.Value = tablo3()
End Sub |