1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| Private Sub CommandButton1_Click()
Dim SD As Worksheet
Dim BASE As Range
Dim i As Integer
Dim der As Integer
Set SD = ThisWorkbook.Sheets("Saisie")
Set BASE = SD.Range("A1")
BASE = BASE.Offset(0)
i = 1
With SD
der = .Cells(.Rows.Count, 1).End(xlUp).Row 'recherche le numéro de la dernière ligne
End With
'rentrer des données obligatoires'
If TextBox1 = "" Or TextBox3 = "" Or ComboBox1 = "" Or ComboBox2 = "" Or ComboBox3 = "" Then
MsgBox "Vous devez remplir toutes les données obligatoires"
End If
If BASE.Offset(i - 1, 0) = "" Then ' Si la première ligne est vide on nomme le nom des colonnes A à E
BASE.Offset(i - 1, 0) = Planteurs.Label1.Caption
BASE.Offset(i - 1, 1) = Planteurs.Label2.Caption
BASE.Offset(i - 1, 2) = Planteurs.Label3.Caption
BASE.Offset(i - 1, 3) = Planteurs.Label4.Caption
BASE.Offset(i - 1, 4) = Planteurs.Label6.Caption
End If
If BASE.Offset(i, 0) <> "" Then ' Si la ligne 2 est déjà remplie on passe à la première ligne vide
i = der
BASE.Offset(i, 0) = Planteurs.TextBox1.Value
BASE.Offset(i, 1) = Planteurs.TextBox2.Value
BASE.Offset(i, 2) = Planteurs.TextBox3.Value
BASE.Offset(i, 3) = Planteurs.TextBox4.Value
BASE.Offset(i, 4) = Planteurs.ComboBox1.Value & "/" & Planteurs.ComboBox2.Value & "/" & Planteurs.ComboBox3.Value
Else
BASE.Offset(i, 0) = Planteurs.TextBox1.Value ' Si la première ligne est vide on y intègre les données
BASE.Offset(i, 1) = Planteurs.TextBox2.Value
BASE.Offset(i, 2) = Planteurs.TextBox3.Value
BASE.Offset(i, 3) = Planteurs.TextBox4.Value
BASE.Offset(i, 4) = Planteurs.ComboBox1.Value & "/" & Planteurs.ComboBox2.Value & "/" & Planteurs.ComboBox3.Value
End If
Unload Me ' On vide l'UserForm des données renseignées
End Sub |
Partager