Private Sub CommandButton2_Click() Dim Annee As String, n As Integer
Dim Wbk As Workbook
If TextBox1.Value = "" Then
MsgBox "Vous devez renseigner la date", vbExclamation, "Erreur"
Exit Sub
End If
If ComboBox1.Value = "" Then
MsgBox "Vous devez renseigner le motif", vbExclamation, "Erreur"
Exit Sub
End If
If TextBox2.Value = "" Then
MsgBox "Vous devez renseigner l'heure de départ", vbExclamation, "Erreur"
Exit Sub
End If
If TextBox5.Value = "" Then
MsgBox "Vous devez renseigner l'heure de rentrée", vbExclamation, "Erreur"
Exit Sub
End If
If TextBox4.Value = "" Then
MsgBox "Vous devez renseigner l'adresse", vbExclamation, "Erreur"
Exit Sub
End If
If TextBox6.Value = "" Then
MsgBox "Vous devez renseigner le secteur", vbExclamation, "Erreur"
Exit Sub
End If
If TextBox15.Value = "" Then
MsgBox "Vous devez renseigner le secteur", vbExclamation, "Erreur"
Exit Sub
End If
Dim rep As Integer
rep = MsgBox("Confirmer vous l'enregistrement?", vbYesNo + vbQuestion, "Confirmation")
If rep = vbYes Then
Annee = Year(TextBox1)
Chemin = ThisWorkbook.Path & "\"
On Error Resume Next
Set Wbk = Workbooks("intervention.xlsx")
Wbk.Activate
If Err <> 0 Then
Workbooks.Open Chemin & "intervention.xlsx", Password:="1234", WriteResPassword:="1234"
End If
On Error GoTo 0
With Wbk.Sheets(Annee)
n = Range("A" & Rows.Count).End(xlUp).Row + 1
.Cells(n, 1).Value = TextBox1.Value
.Cells(n, 2).Value = TextBox2.Value
.Cells(n, 3).Value = TextBox5.Value
.Cells(n, 5).Value = TextBox4.Value
.Cells(n, 6).Value = TextBox6.Value
.Cells(n, 7).Value = ComboBox1.Value
.Cells(n, 8).Value = TextBox15.Value
.Cells(n, 9).Value = TextBox10.Value
.Cells(n, 10).Value = TextBox11.Value
.Cells(n, 11).Value = TextBox12.Value
.Cells(n, 12).Value = TextBox13.Value
.Cells(n, 13).Value = TextBox14.Value
.Cells(n, 14).Value = TextBox7.Value
.Cells(n, 15).Value = TextBox8.Value
.Cells(n, 16).Value = TextBox9.Value
End With
MsgBox "Enregistrement effectué", vbInformation, "Information"
Else: Exit Sub
End If
End Sub