Bonjour,
Eh bien! ... il semble que cela va fonctionner ...
Si ce code te convient, il ne restera qu'à copier le code du bouton1 dans le bouton 2 et d'inverser le numéro des listbox ...
Listbox1 devient Listbox2 et Listbox2 devient Listbox1 > après ce pugilat >> le souci devrait être KO >> et ça devrait fonctionner dans les deux sens ...
Allonge un peu les deux listbox ... ce sera plus agréable à l'oeil ...
Un essai ...
Private Sub CommandButton1_Click()
If Me.ListBox1.ListIndex = -1 Then Exit Sub
If Me.ListBox2.ListCount > 0 Then
For x = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox1.Column(1, Me.ListBox1.ListIndex) = Me.ListBox2.Column(1, x) Then
Me.ListBox2.Column(0, x) = Me.ListBox2.Column(0, x) + 1
Me.ListBox1.List(Me.ListBox1.ListIndex, 0) = Me.ListBox1.List(Me.ListBox1.ListIndex, 0) - 1
If Me.ListBox1.List(Me.ListBox1.ListIndex, 0) = 0 Then Me.ListBox1.RemoveItem Me.ListBox1.ListIndex
Exit Sub
End If
Next x
Me.ListBox2.AddItem
Me.ListBox2.List(Me.ListBox2.ListCount - 1, 0) = 1
Me.ListBox2.List(Me.ListBox2.ListCount - 1, 1) = Me.ListBox1.Column(1, Me.ListBox1.ListIndex)
Me.ListBox1.List(Me.ListBox1.ListIndex, 0) = Me.ListBox1.List(Me.ListBox1.ListIndex, 0) - 1
Else
Me.ListBox2.AddItem
Me.ListBox2.List(Me.ListBox2.ListCount - 1, 0) = 1
Me.ListBox2.List(Me.ListBox2.ListCount - 1, 1) = Me.ListBox1.Column(1, Me.ListBox1.ListIndex)
Me.ListBox1.List(Me.ListBox1.ListIndex, 0) = Me.ListBox1.List(Me.ListBox1.ListIndex, 0) - 1
End If
End Sub
ric