XL 2013 [Résolu] Tri Quick Sort sur dates

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Lone-wolf

XLDnaute Barbatruc
Bonsoir le Forum 🙂

Il y a possiblilité de faire le tri sur l'année au lieu des jours avec la macro de Jacques Boisgontier Quick Sort?

VB:
Private Sub Tri(a(), gauc, droi, colTri)
Dim Temp, C, ref, g, d

   ref = a((gauc + droi) \ 2, colTri)
   g = gauc: d = droi
   Do
     Do While a(g, colTri) < ref: g = g + 1: Loop
     Do While ref < a(d, colTri): d = d - 1: Loop
       If g <= d Then
          For C = LBound(a, 2) To UBound(a, 2)
             Temp = a(g, C): a(g, C) = a(d, C): a(d, C) = Temp
          Next
          g = g + 1: d = d - 1
       End If
   Loop While g <= d
   If g < droi Then Tri a, g, droi, colTri
   If gauc < d Then Tri a, gauc, d, colTri
End Sub
 
Bonsoir Gerard 🙂

@job75

Là tu me pose une colle sérieuse et je vais pas m'en sortir tout seul. 😳

J'ai ensuite ceci qui fait appel

VB:
Private Sub CheckBox3_Click()  'Date
Dim a()
If CheckBox3.Value = True Then
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox4.Value = False
CheckBox5.Value = False

   a = ListBox1.List
   Tri a(), LBound(a), UBound(a), 4
   ListBox1.List = a
End If
End Sub
 
Bonjour,

Code:
Private Sub UserForm_Initialize()
  Me.ListBox1.ColumnCount = [tableau1].Columns.Count
  Me.ListBox1.ColumnWidths = "50;50;20;50;50"
  Me.ListBox1.List = [tableau1].Value
  Me.ListBoxOption.ListStyle = fmListStyleOption
  Me.ListBoxOption.ColumnWidths = "30"
  Me.ListBoxOption.List = Application.Transpose(Range("Tableau1").ListObject.HeaderRowRange.Value)
End Sub

Private Sub ListBoxOption_Click()
   Dim Tbl()
   Tbl = Me.ListBox1.List
   Tri Tbl, LBound(Tbl), UBound(Tbl), Me.ListBoxOption.ListIndex
   Me.ListBox1.List = Tbl
End Sub

Private Sub Tri(a(), gauc, droi, colTri)
   ref = a((gauc + droi) \ 2, colTri)
   g = gauc: d = droi
   Do
     Do While a(g, colTri) < ref: g = g + 1: Loop
     Do While ref < a(d, colTri): d = d - 1: Loop
       If g <= d Then
          For C = LBound(a, 2) To UBound(a, 2)
             Temp = a(g, C): a(g, C) = a(d, C): a(d, C) = Temp
          Next
          g = g + 1: d = d - 1
       End If
   Loop While g <= d
   If g < droi Then Tri a, g, droi, colTri
   If gauc < d Then Tri a, gauc, d, colTri
End Sub

jb
 

Pièces jointes

Bonjour Gerard, Jacques, le Forum 🙂

@BOISGONTIER : merci pour ton intervention. Je vais remplacer la macro par celle-ci.

EDIT: je ne comprends pas pourquoi ça ne marche pas, est-ce que cela viens du faite que tu utilise un tableau? 🙄 . Le formulaire en question est le 2, l'initialisation du tableau ce fait à partir de la macro AutoSize_Columns du module Md_List_Form > Tbl = .Range("a2😛" & .Range("p" & Rows.Count).End(xlUp).Row).Value.
 

Pièces jointes

Dernière édition:
Re Jacques

Cette fois c'est ok. Voici comment j'ai fait pour cette coolonne.

VB:
Private Sub CheckBox3_Click()  'Date de naissance
Dim T, Tb()

    If CheckBox3.Value = True Then
        CheckBox1.Value = False
        CheckBox2.Value = False
        CheckBox4.Value = False
        CheckBox5.Value = False
              
        T = WsB.Range("a2:p" & WsB.Range("p" & Rows.Count).End(xlUp).Row).Value
        ListBox1.List = T

        Tb = ListBox1.List
        Tri Tb, LBound(Tb), UBound(Tb), 4
        ListBox1.List = Tb

        With ListBox1
            For i = 0 To .ListCount - 1
                .List(i, 4) = Format(.List(i, 4), "dd.mm.yyyy")
            Next i
        End With

    End If

End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
3
Affichages
569
Réponses
8
Affichages
650
Réponses
4
Affichages
562
Réponses
4
Affichages
672
Retour