Sub DECLARANT()
Set sh1 = Feuil1
Set sh2 = Feuil2
Set sh3 = Feuil3
te = sh1.[a2].Resize(sh1.[a65000].End(xlUp).Row, 31).Value
nb_decl = 0
For i = 1 To UBound(te, 1)
If te(i, 21) > 0 And Year(te(i, 21)) = sh2.Range("p2") And NOSEM2(te(i, 21)) = sh2.Range("O1") Then
nb_decl = nb_decl + 1
End If
Next i
sh2.Range("C2") = nb_decl
End Sub
Function NOSEM2(D As Date) As Long
D = Int(D)
NOSEM2 = DateSerial(Year(D + (8 - Weekday(D)) Mod 7 - 3), 1, 1)
NOSEM2 = ((D - NOSEM2 - 3 + (Weekday(NOSEM2) + 1) Mod 7)) \ 7 + 1
End Function