Donc ton Select devrait être : Case 1 to 26, 31 To yune fonction qui doit ce faire des feuilles 1 à 26 et de 31 à 39 , mais pas 27 à 30.
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
Est-il possible de nommer les feuilles que je veux exclure ?
Par exemple dire que je ne veux pas des feuilles sheets.name = "octobre","novembre", "décembre"
merci
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
If sh.Name <> "octobre" And sh.Name <> "novembre" And sh.Name <> "décembre" Then ....
Option Explicit
Function periode(Optional lig As Long = 2)
Application.Volatile 'selon le besoin…
Dim c As Range, Cpte As Integer
Dim t() As Variant, ws As Object, i as integer
t = Array("janvier", "février", "mars")
Application.DisplayAlerts = False
For Each ws In t
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
Next ws
Application.DisplayAlerts = True
End Sub