If Not Intersect(Target, Range("F34:N" & Cells(Rows.Count, "A").End(xlUp).Row)) Is Nothing Then
If WorksheetFunction.CountIf(Rows(Target.Row).Columns("A:E"), "<>") = 4 Then
If WorksheetFunction.CountIf(Rows(Target.Row).Columns("F:N"), "<>") < 9 Then
If Range("P" & Target.Row) = "" Then
Application.EnableEvents = False
Z = Application.InputBox("Un commentaire est obligatoire" & vbLf & "pour cette ligne")
If Not Z = False Then Range("P" & Target.Row) = Z
Application.EnableEvents = True
End If
End If
End If
End If
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not ThisWorkbook.Saved Then
Select Case MsgBox("Voulez-vous enregistrer ce Classeur ?", vbQuestion + vbYesNoCancel)
Case vbYes: ThisWorkbook.Save
Case vbCancel: Cancel = True
Case vbNo: ThisWorkbook.Saved = True ' On quitte sans sauvegarder
End Select
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Ligne As Range
For Each Ligne In Range("A34:S" & Cells(Rows.Count, "A").End(xlUp).Row).Rows
If WorksheetFunction.CountIf(Ligne.Columns("F:N"), "<>") < 9 Then
If Ligne.Columns("P") = vbNullString Then
Z = Application.InputBox("Un commentaire est obligatoire" & vbLf & "pour le n°Of " & Ligne.Columns("D"))
If Not (Z = False Or Trim(Z) = vbNullString) Then
Application.EnableEvents = False
Ligne.Columns("P") = Z
Application.EnableEvents = True
Else
Cancel = True
Exit For
End If
End If
End If
Next
If Not Cancel Then ThisWorkbook.Save
End Sub
Il me semblait plus convivial de demander à entrer un commentaire au fur et à mesure de la saisie,Cela ne répond malheureusement pas à ma question.
If Not Intersect(Target, Range("F34:N" & Cells(Rows.Count, "A").End(xlUp).Row)) Is Nothing Then
If WorksheetFunction.CountIf(Rows(Target.Row).Columns("A:E"), "<>") = 4 Then
If WorksheetFunction.CountIf(Rows(Target.Row).Columns("F:N"), "<>") < 9 Then
If Range("P" & Target.Row) = "" Then
Application.EnableEvents = False
Z = Application.InputBox("Un commentaire est obligatoire" & vbLf & "pour cette ligne")
If Not Z = False Then Range("P" & Target.Row) = Z Else Target.ClearContents
Application.EnableEvents = True
End If
End If
End If
End If
ActiveSheet.Unprotect ("2230")Ligne.Columns("O") = ZActiveSheet.Protect ("2230")