Trie d'un tableau dans l'ordre croissant

Bonjour,

Quelqu'un saurait comment avec un code vba on pourrait trier un tableau du minimum au maximum , sachant qu'il y a des valeurs qui peuvent se répéter et que les valeur dérivent d'une formule dans la fonction trie d'excel seul ne marche pas.

merci d'avance

cordialement

Hello,

@rag02700,

Ci-jointe le fichier contenant le tableau à trier

merci

21tableau.xlsx (8.70 Ko)

cordialement

Bonjour,

Voilà une proposition.

25tableau.xlsx (10.43 Ko)

Pardon c'est sans code VBA, je n'ai pas lu attentivement... Mais le résultat est là

Hello,

j'ai rien pigé à ton fichier, les chiffres dans la colonne G ça veut dire quoi ?

Salut,

C'est juste un tableau que je voudrais trier avec un code vba du min au max, l'option trie d'excel ne fonctionne pas sur les cases contenant des fromules

merci

cordialement

Tu peux utiliser un Quicksort.

En voici un exemple trouvé sur le net :

Récupération de la colonne à trier dans cette exemple de C1 à la dernière ligne de la colonne C + lancement de la procedure de tri + restitution dans la plage A1:A6

Sub ProcessData_Quicksort()
'Example macro to show you how to add a column of data to an array
'and sort the data from smallest to largest using VBA Quicksort.
Dim MyData() As Variant
Dim i As Long, LastRow As Long

'Store column of data into array
LastRow = Range("C" & Rows.Count).End(xlUp).Row
ReDim MyData(1 To LastRow)
For i = 1 To LastRow
    MyData(i) = Range("C" & i)
Next i

'Now sort your array using the VBA Quicksort macro
Call Quicksort(MyData(), LBound(MyData), UBound(MyData))
'
'From here on, your "MyData" array is sorted from smallest to largest
'
Range("a1:a6").Value = WorksheetFunction.Transpose(MyData)
End Sub

Procédure de trie en elle même (de toute beauté :) )

Sub Quicksort(vArray As Variant, arrLbound As Long, arrUbound As Long)
'Sorts a one-dimensional VBA array from smallest to largest
'using a very fast quicksort algorithm variant.
Dim pivotVal As Variant
Dim vSwap    As Variant
Dim tmpLow   As Long
Dim tmpHi    As Long

tmpLow = arrLbound
tmpHi = arrUbound
pivotVal = vArray((arrLbound + arrUbound) \ 2)

While (tmpLow <= tmpHi) 'divide
   While (vArray(tmpLow) < pivotVal And tmpLow < arrUbound)
      tmpLow = tmpLow + 1
   Wend

   While (pivotVal < vArray(tmpHi) And tmpHi > arrLbound)
      tmpHi = tmpHi - 1
   Wend

   If (tmpLow <= tmpHi) Then
      vSwap = vArray(tmpLow)
      vArray(tmpLow) = vArray(tmpHi)
      vArray(tmpHi) = vSwap
      tmpLow = tmpLow + 1
      tmpHi = tmpHi - 1
   End If
Wend

  If (arrLbound < tmpHi) Then Quicksort vArray, arrLbound, tmpHi 'conquer
  If (tmpLow < arrUbound) Then Quicksort vArray, tmpLow, arrUbound 'conquer
End Sub
Rechercher des sujets similaires à "trie tableau ordre croissant"