'*******************************
Private Sub UserForm_Initialize()
'on récupère le supplier en B1
supplier = Worksheets("supplier form").Range("B1")
' et on rempli les Textbox et combo avec les data de la feuille informations
With Sheets("informations")
Set Z = .[A3:A1048576].Find(what:=supplier)
If Not Z Is Nothing Then
Ligne = Z.Row
TextBox1 = .Cells(Ligne, 3)
TextBox2 = .Cells(Ligne, 4)
TextBox3 = .Cells(Ligne, 5)
TextBox4 = .Cells(Ligne, 6)
TextBox5 = .Cells(Ligne, 7)
TextBox6 = .Cells(Ligne, 8)
ComboBox1 = .Cells(Ligne, 9).Value
ComboBox2 = .Cells(Ligne, 10).Value
TextBox7 = .Cells(Ligne, 11)
TextBox8 = .Cells(Ligne, 12)
TextBox9 = .Cells(Ligne, 13)
Else
MsgBox "supplier inexistant, va donc être créé"
End If
End With
End Sub
Private Sub CommandButton2_Click()
'pour quitter le userform
Unload Me
End Sub
Private Sub CommandButton1_Click()
'clic sur bouton "modifier"
Dim supplier As String
Dim Z As Range
'on récupère le nom du supplier en B1
supplier = Worksheets("supplier form").Range("B1")
With Sheets("informations")
Set Z = .[A3:A1048576].Find(what:=supplier)
's'il existe déjà, on récupère sa ligne
If Not Z Is Nothing Then
Ligne = Z.Row
'sinon on se place à la fin
Else
Ligne = .Range("A1048576").End(xlUp).Offset(1, 0).Row
End If
On Error Resume Next
'on recopie les textbox dans la feuille Informations
.Cells(Ligne, 1) = Worksheets("supplier form").Range("B1").Value
.Cells(Ligne, 2) = Worksheets("supplier form").Range("F1").Value
.Cells(Ligne, 3) = TextBox1.Value
.Cells(Ligne, 4) = TextBox2.Value
.Cells(Ligne, 5) = TextBox3.Value
.Cells(Ligne, 6) = TextBox4.Value
.Cells(Ligne, 7) = TextBox5.Value
.Cells(Ligne, 8) = TextBox6.Value
.Cells(Ligne, 9) = ComboBox1.Value
.Cells(Ligne, 10) = ComboBox2.Value
.Cells(Ligne, 11) = TextBox7.Value
.Cells(Ligne, 12) = TextBox8.Value
.Cells(Ligne, 13) = TextBox9.Value
End With
End Sub