OVH Cloud OVH Cloud

Listbox

2 réponses
Avatar
FB
Me revoila avec mon tri de listbox.....

Bjr tout le monde


Est ce que quelqu'un connais un routine vba pour trié le contenu d'une
listbox (situé dans un userform) sans passé par une feuille excel

il faut certainement passé par les array mais j'y connais rien dans ce
domaine...

Merci pour toute aide apportée

2 réponses

Avatar
michdenis
Bonjour FB,


IL y a ceci provenant de John Walkenbach(Auteur de nombreux livres sur excel)
'------------------------
Sub SortListBox(oLb As MSForms.ListBox)
Dim vaItems As Variant
Dim i As Long, j As Long
Dim vTemp As Variant

'Put the items in a variant array
vaItems = oLb.List

'Steal code from John Walkenbach's Excel Power Programming
'with VBA to sort the array
For i = LBound(vaItems, 1) To UBound(vaItems, 1) - 1
For j = i + 1 To UBound(vaItems, 1)
If vaItems(i, 0) > vaItems(j, 0) Then
vTemp = vaItems(i, 0)
vaItems(i, 0) = vaItems(j, 0)
vaItems(j, 0) = vTemp
End If
Next j
Next i

'Clear the listbox
oLb.Clear

'Add the sorted array back to the listbox
For i = LBound(vaItems, 1) To UBound(vaItems, 1)
oLb.AddItem vaItems(i, 0)
Next i

End Sub
'------------------------

Pour appeler cette procédure, il s'agit s'appeler cette dernère en passant un Combobox comme argument
SortListBox Me.Combobox1




Salutations!





"FB" a écrit dans le message de news:
Me revoila avec mon tri de listbox.....

Bjr tout le monde


Est ce que quelqu'un connais un routine vba pour trié le contenu d'une
listbox (situé dans un userform) sans passé par une feuille excel

il faut certainement passé par les array mais j'y connais rien dans ce
domaine...

Merci pour toute aide apportée
Avatar
FB
Merci à toi michdenis
je vais me renseigner pour me procurer les livres de john walkenbach ....

Merci


Bonjour FB,


IL y a ceci provenant de John Walkenbach(Auteur de nombreux livres sur excel)
'------------------------
Sub SortListBox(oLb As MSForms.ListBox)
Dim vaItems As Variant
Dim i As Long, j As Long
Dim vTemp As Variant

'Put the items in a variant array
vaItems = oLb.List

'Steal code from John Walkenbach's Excel Power Programming
'with VBA to sort the array
For i = LBound(vaItems, 1) To UBound(vaItems, 1) - 1
For j = i + 1 To UBound(vaItems, 1)
If vaItems(i, 0) > vaItems(j, 0) Then
vTemp = vaItems(i, 0)
vaItems(i, 0) = vaItems(j, 0)
vaItems(j, 0) = vTemp
End If
Next j
Next i

'Clear the listbox
oLb.Clear

'Add the sorted array back to the listbox
For i = LBound(vaItems, 1) To UBound(vaItems, 1)
oLb.AddItem vaItems(i, 0)
Next i

End Sub
'------------------------

Pour appeler cette procédure, il s'agit s'appeler cette dernère en passant un Combobox comme argument
SortListBox Me.Combobox1




Salutations!





"FB" a écrit dans le message de news:
Me revoila avec mon tri de listbox.....

Bjr tout le monde


Est ce que quelqu'un connais un routine vba pour trié le contenu d'une
listbox (situé dans un userform) sans passé par une feuille excel

il faut certainement passé par les array mais j'y connais rien dans ce
domaine...

Merci pour toute aide apportée