Private Sub Worksheet_Activate()
Dim An%, tablo, i&, dat1 As Variant, dat2 As Variant, nom$, dat&
An = Val([D2])
Application.ScreenUpdating = False
Application.EnableEvents = False 'désactive les évènements
Range("C5:C35,E5:E35,G5:G35,I5:I35,K5:K35,M5:M35,O5:O35,Q5:Q35,S5:S35,U5:U35,W5:W35,Y5:Y35") = "" 'RAZ
If An > 0 Then
tablo = [resa].Resize(, 9) 'tableau structuré
For i = 1 To UBound(tablo)
dat1 = tablo(i, 5): dat2 = tablo(i, 6): nom = tablo(i, 9)
If IsDate(dat1) And IsDate(dat2) Then
If Year(dat1) = An Or Year(dat2) = An Then
dat1 = Application.Max(CLng(CDate(dat1)), DateSerial(An, 1, 1))
dat2 = Application.Min(CLng(CDate(dat2)), DateSerial(An, 12, 31))
For dat = dat1 To dat2
Cells(4 + Day(dat), 1 + 2 * Month(dat)) = nom
Next dat
End If
End If
Next i
End If
Application.EnableEvents = True 'réactive les évènements
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Worksheet_Activate 'lance la macro
End Sub