Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [C4,E4,M8]) Is Nothing Then
RCN [M8], [T8]
'autres macros éventuellement
End If
End Sub
Sub RCN(debut As Range, resu As Range)
Dim mois&, an&, jours&, i&
mois = Int(Val(CStr([C4])))
an = Int(Abs(Val(CStr([E4]))))
If mois < 1 Or mois > 12 Then _
MsgBox "Entrez un mois entre 1 et 12": resu = "": Exit Sub
If DateSerial(an, mois, 1) >= debut Then
Application.ScreenUpdating = False
Application.EnableEvents = False 'désactive les événements
[C4] = 1
[E4] = Year(debut)
'---déduction des mois du début---
If Month(debut) > 1 Then _
jours = -Application.CountIf([E15:E45].Resize(, 3 * Month(debut) - 3), "N")
'---années entières---
For i = [E4] To an - 1
[E4] = i
jours = jours + Application.CountIf([E15:AN45], "N")
Next
'---dernière année---
[E4] = an
jours = jours + Application.CountIf([E15:E45].Resize(, 3 * mois), "N")
[C4] = mois
Application.EnableEvents = True
End If
resu = Int(jours / 10)
End Sub