Option Explicit
'Pour le formulaire
Private Sub UserForm_Initialize()
With ComboBox1
.List = Range("Tableau1").ListObject.ListColumns(1).Range.Value
.RemoveItem (0)
End With
End Sub
'Pour la liste déroulante Code client
Private Sub ComboBox1_Change()
Dim x&
If ComboBox1.ListIndex = -1 Then Exit Sub
x = ComboBox1.ListIndex + 1
With Range("Tableau1").Rows(x)
TextBox1 = .Cells(1, 2): TextBox2 = .Cells(1, 3)
TextBox3 = .Cells(1, 4): TextBox4 = .Cells(1, 5)
TextBox5 = .Cells(1, 6)
End With
End Sub
'Pour le bouton Nouveau Client
Private Sub CommandButton1_Click()
Dim r
If ComboBox1.ListIndex > -1 Then Exit Sub 'pour ne pas ajouter un client deja existant
Set r = Range("Tableau1").ListObject.ListRows.Add.Range
r.Value = Array(ComboBox1, TextBox1, TextBox2, TextBox3, TextBox4, TextBox5)
End Sub
'Pour le bouton Modifier
Private Sub CommandButton2_Click()
Dim r, x
If ComboBox1.ListIndex = -1 Then Exit Sub 'si pas de selection dans la combo le bouton ne fait rien
x = ComboBox1.ListIndex + 1
Set r = Range("Tableau1").ListObject.ListRows(x).Range
r.Value = Array(ComboBox1, TextBox1, TextBox2, TextBox3, TextBox4, TextBox5)
End Sub
'Pour le bouton quitter
Private Sub Comandbotton3_click()
Unload Me
End Sub