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
| Public Flag As Boolean
Dim nCA&, nCAJ&, nCAN&, n12h&
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect([C9:M46], Target) Is Nothing Then Exit Sub
nCA = Application.CountIf(Intersect([9:46], Target.EntireColumn), "CA")
nRPM = Application.CountIf(Intersect([9:46], Target.EntireColumn), "RPM")
nCAJ = Application.CountIf(Intersect([9:46], Target.EntireColumn), "CAJ*")
nCAN = Application.CountIf(Intersect([9:46], Target.EntireColumn), "*CAN")
If (nCA + nCAJ + nRPM) > 12 Or (nCA + nCAN + nRPM) > 12 Then
MsgBox "Le nombre maximal de 12 CA total est déjà atteint !", vbCritical, "Saisie CA"
Target.Interior.Color = RGB(255, 255, 255)
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
End If
End Sub"
* Et le 2ème qui n'autorise pas plus de 5 12h par jour
"Public Flag As Boolean
Dim n12h&
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect([C9:M46], Target) Is Nothing Then Exit Sub
n12h = Application.CountIf(Intersect([9:46], Target.EntireColumn), "12h")
If n12h > 5 Then
MsgBox "Le nombre maximal de 12h pour ce jour est déjà atteint !", vbCritical, "Saisie 12h"
Target.Interior.Color = RGB(255, 255, 255)
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
End If
End Sub |
Partager