Private Sub Worksheet_Calculate()
Dim efface As Boolean, deb&, dat&, i&, a(1 To 118, 1 To 2)
efface = Year(Date) <> Year(Val(CStr([Jour])))
Application.ScreenUpdating = False
[A3].Resize(UBound(a), 2).NumberFormat = "General"
deb = 3
For dat = DateSerial([A1], 1, 1) To DateSerial([A1], 12, 31)
If Weekday(dat) = 3 Then
i = i + 1
a(i, 1) = dat
If efface Then a(i, 2) = Empty Else a(i, 2) = Cells(i + 2, 2)
Cells(i + 2, 1).NumberFormat = """Mardi"" * dd/mm/yyyy"
ElseIf Weekday(dat) = 4 Then
i = i + 1
a(i, 1) = dat
If efface Then a(i, 2) = Empty Else a(i, 2) = Cells(i + 2, 2)
Cells(i + 2, 1).NumberFormat = """Mercredi"" * dd/mm/yyyy"
End If
If Month(dat) < Month(dat + 1) Then
i = i + 1
a(i, 1) = 0
a(i, 2) = "=SUM(B" & deb & ":B" & i + 1 & ")"
Cells(i + 2, 1).NumberFormat = """Total"""
deb = i + 3
End If
Next dat
a(i + 1, 1) = 0
a(i + 1, 2) = "=SUM(B" & deb & ":B" & i + 2 & ")"
Cells(i + 3, 1).NumberFormat = """Total"""
Application.EnableEvents = False
With [A3].Resize(UBound(a))
.Resize(, 2) = a
.Resize(, 2).FormatConditions.Delete
ThisWorkbook.Names.Add "Jour", Date
ThisWorkbook.Names.Add "Mini", "=MIN(ABS(" & .Address & "-Jour))"
.FormatConditions.Add xlExpression, Formula1:="=ABS(A3-Jour)=Mini"
.FormatConditions(1).Interior.Color = vbRed
.FormatConditions(1).Font.Color = vbWhite
.FormatConditions(1).Font.Bold = True
.Resize(, 2).FormatConditions.Add xlExpression, Formula1:="=""""&$A3=""0"""
.Resize(, 2).FormatConditions(2).Interior.Color = vbCyan
.Resize(, 2).FormatConditions(2).Font.Bold = True
End With
Columns("A:B").AutoFit
Application.EnableEvents = True
End Sub