Private Sub CommandButton2_Click()
Dim LigneEstVide As Boolean, xrg As Range
If ListBox1.ListIndex >= 0 Then
'un client est sélectionné dans la listbox1
'on vérifie si la ligne courante du tableau est vide ou non
'si oui, alors on rajoute le client à la première ligne vide
'sinon on modifie la cellule active.
With Sheets("COMMANDES")
Set xrg = .Range(.Cells(ActiveCell.Row, "a"), .Cells(ActiveCell.Row, "k"))
LigneEstVide = Application.WorksheetFunction.CountA(xrg) = 0
If Not LigneEstVide Then
'l'enregistrement existe déjà
ActiveCell = ListBox1
Else
'on recherche la première ligne vide
Set xrg = .Cells(11, "a").Resize(, Columns("a:k").Count)
Do
Set xrg = xrg.Offset(1)
LigneEstVide = Application.WorksheetFunction.CountA(xrg) = 0
Loop Until LigneEstVide
xrg(1, 1) = ListBox1
End If
End With
End If
' ferme formulaire
Unload Me
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
CommandButton2_Click
End Sub