anass1
XLDnaute Junior
Bonjour,
SVP, j'ai un problème pour trier les colonnes de listbox; Je veux trier trois colonnes comme dans l'image 1
J'ai utilisé ce code mais il ne trie pas correctement la sixième colonne; Parce qu'il contient un vide.
Merci
Img1:
		
		
	
	

Code:
	
	
	
	
	
		
Problème:

	
		
			
		
		
	
				
			SVP, j'ai un problème pour trier les colonnes de listbox; Je veux trier trois colonnes comme dans l'image 1
J'ai utilisé ce code mais il ne trie pas correctement la sixième colonne; Parce qu'il contient un vide.
Merci
Img1:

Code:
		VB:
	
	
	Private Sub UserForm_Initialize()
   Dim y As Long
    ListBox1.ColumnCount = 6
    'ListBox1.ColumnHeads = True
    y = Cells(Rows.Count, "C").End(xlUp).Row
    ListBox1.List = Range("A2:F" & y).Value
'==================================================
    Dim a(), b(), c()
    a = Me.ListBox1.List
    Call tri(a(), LBound(a), UBound(a), 6, 0)
    b = a
    Call tri(b(), LBound(a), UBound(b), 6, 2)
    c = b
    Call tri(c(), LBound(a), UBound(c), 6, 5)
   Me.ListBox1.List = c
   ListBox1.TopIndex = ListBox1.ListCount - 1
    End Sub
Sub tri(x(), gauc, droi, NbCol, colTri)        ' Quick sort (JBGontier)
ref = x((gauc + droi) \ 2, colTri)
g = gauc: D = droi
    Do
        Do While x(g, colTri) < ref: g = g + 1: Loop
        Do While ref < x(D, colTri): D = D - 1: Loop
        If g <= D Then
            For c = 0 To NbCol - 1
                temp = x(g, c): x(g, c) = x(D, c): x(D, c) = temp
            Next
            g = g + 1: D = D - 1
        End If
    Loop While g <= D
    If g < droi Then Call tri(x, g, droi, NbCol, colTri)
    If gauc < D Then Call tri(x, gauc, D, NbCol, colTri)
End SubProblème:

Pièces jointes
			
				Dernière édition: 
			
		
	
								
								
									
	
		
			
		
		
	
	
	
		
			
		
		
	
								
							
							 
	 
 
		 
 
		
 
 
		
 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		