Merci de ton aide
Je travail sur 2 Macros "CPPériode & CPConsécutifs" qui je pense peuvent être simplifié
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
| Function CPPériode(Mai As Range, Juin As Range, Juillet As Range, Août As Range, Septembre As Range, Octobre As Range) As Double
Dim Cellule As Range
For Each Cellule In Mai
If Cellule = "CP" Then CPPériode = CPPériode + 1
If Cellule = "D" Then CPPériode = CPPériode + 0.5
Next
For Each Cellule In Juin
If Cellule = "CP" Then CPPériode = CPPériode + 1
If Cellule = "D" Then CPPériode = CPPériode + 0.5
Next
For Each Cellule In Juillet
If Cellule = "CP" Then CPPériode = CPPériode + 1
If Cellule = "D" Then CPPériode = CPPériode + 0.5
Next
For Each Cellule In Août
If Cellule = "CP" Then CPPériode = CPPériode + 1
If Cellule = "D" Then CPPériode = CPPériode + 0.5
Next
For Each Cellule In Septembre
If Cellule = "CP" Then CPPériode = CPPériode + 1
If Cellule = "D" Then CPPériode = CPPériode + 0.5
Next
For Each Cellule In Octobre
If Cellule = "CP" Then CPPériode = CPPériode + 1
If Cellule = "D" Then CPPériode = CPPériode + 0.5
Next
End Function |
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 102
| Function CPConsécutifs(Mai As Range, Juin As Range, Juillet As Range, Août As Range, Septembre As Range, Octobre As Range) As Double
Dim CP As Boolean
CP = False
Dim WE As Boolean
WE = False
Dim Compteur As Integer
Compteur = 0
Dim EnCours As Integer
EnCours = 0
For Each Cellule In Mai
If Cellule = "CP" Then
EnCours = EnCours + 1
CP = True
End If
If Cellule = "WE" And CP = True Then
WE = True
End If
If Cellule <> "WE" And Cellule <> "CP" And CP = True Then
If CPConsécutifs < EnCours Then CPConsécutifs = EnCours
EnCours = 0
WE = False
CP = False
End If
Next
Dim Cellule As Range
For Each Cellule In Juin
If Cellule = "CP" Then
EnCours = EnCours + 1
CP = True
End If
If Cellule = "WE" And CP = True Then
WE = True
End If
If Cellule <> "WE" And Cellule <> "CP" And CP = True Then
If CPConsécutifs < EnCours Then CPConsécutifs = EnCours
EnCours = 0
WE = False
CP = False
End If
Next
For Each Cellule In Juillet
If Cellule = "CP" Then
EnCours = EnCours + 1
CP = True
End If
If Cellule = "WE" And CP = True Then
WE = True
End If
If Cellule <> "WE" And Cellule <> "CP" And CP = True Then
If CPConsécutifs < EnCours Then CPConsécutifs = EnCours
EnCours = 0
WE = False
CP = False
End If
Next
For Each Cellule In Août
If Cellule = "CP" Then
EnCours = EnCours + 1
CP = True
End If
If Cellule = "WE" And CP = True Then
WE = True
End If
If Cellule <> "WE" And Cellule <> "CP" And CP = True Then
If CPConsécutifs < EnCours Then CPConsécutifs = EnCours
EnCours = 0
WE = False
CP = False
End If
Next
For Each Cellule In Septembre
If Cellule = "CP" Then
EnCours = EnCours + 1
CP = True
End If
If Cellule = "WE" And CP = True Then
WE = True
End If
If Cellule <> "WE" And Cellule <> "CP" And CP = True Then
If CPConsécutifs < EnCours Then CPConsécutifs = EnCours
EnCours = 0
WE = False
CP = False
End If
Next
For Each Cellule In Octobre
If Cellule = "CP" Then
EnCours = EnCours + 1
CP = True
End If
If Cellule = "WE" And CP = True Then
WE = True
End If
If Cellule <> "WE" And Cellule <> "CP" And CP = True Then
If CPConsécutifs < EnCours Then CPConsécutifs = EnCours
EnCours = 0
WE = False
CP = False
End If
If CPConsécutifs < EnCours Then CPConsécutifs = EnCours
Next
End Function |
en oubliant pas de rajouter WE, même sur les fériés
cela va me permetre d'utilisé une formule de type :
=SI(CPConsécutifs(Mai;Juin;Juillet;Aout;Septembre;Octobre)>=12;SI(24-CPPériode(Mai;Juin;Juillet;Aout;Septembre;Octobre)>=5;2;SI(24-CPPériode(Mai;Juin;Juillet;Aout;Septembre;Octobre)>2;1;0));0)
Encore merci de ton aide
Partager