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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Plage As Range
Dim Plage_Bloc1 As Range
Dim Plage_Bloc2 As Range
Dim Plage_Bloc3 As Range
Dim Plage_Bloc4 As Range
Dim Cel_Bloc1 As Range
Dim Cel_Bloc2 As Range
Dim Cel_Bloc3 As Range
Dim Cel_Bloc4 As Range
'seulement sur les colonnes B à F
If Target.Column = 1 Or Target.Column > 6 Then Exit Sub
With Target
'défini la plage sur laquelle agir
Set Plage = Union(Range(Cells(8, .Column), Cells(10, .Column)), _
Range(Cells(13, .Column), Cells(15, .Column)), _
Range(Cells(18, .Column), Cells(20, .Column)), _
Range(Cells(23, .Column), Cells(34, .Column)))
'défini les plages de recherche
Set Plage_Bloc1 = Range(Cells(8, .Column), Cells(10, .Column))
Set Plage_Bloc2 = Range(Cells(13, .Column), Cells(15, .Column))
Set Plage_Bloc3 = Range(Cells(18, .Column), Cells(20, .Column))
Set Plage_Bloc4 = Range(Cells(23, .Column), Cells(34, .Column))
'si dans le bloc 1
If Not Intersect(Target, Plage) Is Nothing Then
'recherche la personne dans les différents blocs
'si trouvée, affecte la valeur entrée dans la cellule active (qui peut être elle même)
Set Cel_Bloc1 = Plage_Bloc1.Offset(0, -.Column + 1).Find(Cells(.Row, 1), , xlValues, xlWhole)
If Not Cel_Bloc1 Is Nothing Then
Application.EnableEvents = False
Cel_Bloc1.Offset(0, .Column - 1) = .Value
Application.EnableEvents = True
End If
Set Cel_Bloc2 = Plage_Bloc2.Offset(0, -.Column + 1).Find(Cells(.Row, 1), , xlValues, xlWhole)
If Not Cel_Bloc2 Is Nothing Then
Application.EnableEvents = False
Cel_Bloc2.Offset(0, .Column - 1) = .Value
Application.EnableEvents = True
End If
Set Cel_Bloc3 = Plage_Bloc3.Offset(0, -.Column + 1).Find(Cells(.Row, 1), , xlValues, xlWhole)
If Not Cel_Bloc3 Is Nothing Then
Application.EnableEvents = False
Cel_Bloc3.Offset(0, .Column - 1) = .Value
Application.EnableEvents = True
End If
Set Cel_Bloc4 = Plage_Bloc4.Offset(0, -.Column + 1).Find(Cells(.Row, 1), , xlValues, xlWhole)
If Not Cel_Bloc4 Is Nothing Then
Application.EnableEvents = False
Cel_Bloc4.Offset(0, .Column - 1) = .Value
Application.EnableEvents = True
End If
'si dans un des blocs l'effectif minimal est déjà atteint, affiche le message et supprime
'l'abscence de la personne
If Application.WorksheetFunction.CountBlank(Plage_Bloc1) < 1 _
Or Application.WorksheetFunction.CountBlank(Plage_Bloc2) < 1 _
Or Application.WorksheetFunction.CountBlank(Plage_Bloc3) < 1 _
Or Application.WorksheetFunction.CountBlank(Plage_Bloc4) < 6 Then
MsgBox "Permanence minimale atteinte !"
Application.EnableEvents = False 'gèle
On Error Resume Next 'évite l'erreur de la personne abscente d'un des blocs
Cel_Bloc1.Offset(0, .Column - 1) = ""
Cel_Bloc2.Offset(0, .Column - 1) = ""
Cel_Bloc3.Offset(0, .Column - 1) = ""
Cel_Bloc4.Offset(0, .Column - 1) = ""
Application.EnableEvents = True 'rétabli
End If
End If
End With
End Sub |