Private Sub CheckBox1_Click()
Dim dates As Range, planning As Range, debut As Range, fin As Range, today As Range
Set dates = Sheets("planning RH").Range("dates")
Set planning = Sheets("planning RH").Range("planning")
Set debut = Sheets("planning RH").Range("debut")
Set fin = Sheets("planning RH").Range("fin")
Set today = Sheets("planning RH").Range("today")
For x = 1 To 40
For y = 1 To 180
If CheckBox1.Value = True _
And (dates.Cells(1, y).Value >= debut.Cells(1, 1)) _
And (dates.Cells(1, y).Value <= fin.Cells(1, 1)) Then
planning.Cells(1, y).Interior.ColorIndex = 3
End If
If CheckBox1.Value = False _
And (dates.Cells(1, y).Value >= debut.Cells(1, 1)) _
And (dates.Cells(1, y).Value <= fin.Cells(1, 1)) Then
If (dates.Cells(1, y).Value >= debut.Cells(x, 1)) _
And (dates.Cells(1, y).Value <= fin.Cells(x, 1)) _
And (dates.Cells(1, y).Value <= fin.Cells(x, 1)) Then
planning.Cells(x, y).Interior.ColorIndex = 6
End If
'les tâches du jour en orange
If (dates.Cells(1, y).Value = today.Cells(x, 1)) _
And (dates.Cells(1, y).Value >= debut.Cells(x, 1)) _
And (dates.Cells(1, y).Value <= fin.Cells(x, 1)) Then
planning.Cells(x, y).Interior.ColorIndex = 45
End If
'les week-ends en gris
If Weekday((dates.Cells(1, y)), vbMonday) > 5 Then
planning.Cells(x, y).Interior.ColorIndex = 15
End If
End If
Next y
Next x
End Sub