Bonsoir tout le monde,
Voici une une autre proposition (sans USF) :
Private Sub CommandButton1_Click()
'Reculer un élément de la liste
Dim Temp As String
If ListBox1.ListCount = 0 Then Exit Sub
Temp = ListBox1.Text
If ListBox1.ListIndex <= 0 Then
ListBox1.List(0) = ListBox1.List(ListBox1.ListCount - 1)
ListBox1.List(ListBox1.ListCount - 1) = Temp
ListBox1.ListIndex = ListBox1.ListCount - 1
Else
ListBox1.List(ListBox1.ListIndex) = ListBox1.List(ListBox1.ListIndex - 1)
ListBox1.List(ListBox1.ListIndex - 1) = Temp
ListBox1.ListIndex = ListBox1.ListIndex - 1
End If
End Sub
Private Sub CommandButton2_Click()
'Avancer un élément de la liste
Dim Temp As String
If ListBox1.ListCount = 0 Then Exit Sub
Temp = ListBox1.Text
If ListBox1.ListIndex = ListBox1.ListCount - 1 Then
ListBox1.List(ListBox1.ListIndex) = ListBox1.List(0)
ListBox1.List(0) = Temp
ListBox1.ListIndex = 0
Else
ListBox1.List(ListBox1.ListIndex) = ListBox1.List(ListBox1.ListIndex + 1)
ListBox1.List(ListBox1.ListIndex + 1) = Temp
ListBox1.ListIndex = ListBox1.ListIndex + 1
End If
End Sub
Pour que cela marche, il ne faut pas que la zone de liste soit remplie avec sa propriété "ListFillRange", il faut utiliser la méthode "AddItem".
Par exemple comme ceci :
Private Sub Workbook_Open()
Dim I As Integer
Feuil3.ListBox1.Clear
For I = 1 To 7
Feuil3.ListBox1.AddItem Feuil3.Cells(I, 1).Text
Next
Feuil3.ListBox1.ListIndex = 0
End Sub
A+
Horatio