Option Explicit
Function periode(Optional lig As Long = 2)
Application.Volatile 'selon le besoin…
Dim c As Range, t As Integer, Cpte As Integer, i As Byte, y As Byte
y = Worksheets.Count
For i = 1 To y
Select Case i
Case 1 To 27, 31 To y
If lig = 0 Then lig = 4
Set c = Sheets(i).Range("C" & lig)
Do While IsDate(Sheets(i).Cells(1, c.Column))
If c = "RF" Or c = "P1" Or c = "" Then
Cpte = Cpte + 1
Else
'If periode < Cpte Then periode = Cpte
Cpte = 0
End If
If periode < Cpte Then periode = Cpte
Set c = c(1, 3)
Loop
End Select
Next i
End Function