Bonjour,
Avec un fichier joint (sans données confidentielles) ce serait plus simple sinon, essayez ceci:
Option Compare Text
Sub ComptColor()
Dim DerLig As Long, DerCol As Long
Dim Total As Long, i As Long, j As Long
DerLig = Range("A" & Rows.Count).End(xlUp).Row
DerCol = 315 'Colonne LC
For i = 2 To DerLig
Cpt = 0
For j = 2 To DerCol
If Cells(i, j).Interior.ColorIndex = 3 And Cells(i, j).Value <> "X" And Cells(i, j).Value <> "F" Then
Cpt = Cpt + 1
Total = Total + 1
End If
Next j
Next i
Range("LD1").Value = Total
End Sub
Option Compare Text
**********************************************************************************************************************
Si la couleur rouge est obtenue par une mise en forme conditionnelle, le code ci-dessus n'est pas valable, dans ce cas il faudrait nous dire quel est le contenu de la cellule qui permet de passer la cellule en rouge.
Exemple de code si la cellule contient "CA" pour congé annuel, dans ce cas on compte la présence des "CA" et non plus la couleur rouge:
Sub ComptColor2()
Dim DerLig As Long
Dim Total As Long, i As Long, j As Long
DerLig = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To DerLig
Cells(i, "LD") = Application.WorksheetFunction.CountIf(Range(Cells(i, 2), Cells(i, "LC")), "CA")
Next i
Range("LD1").Value = Application.WorksheetFunction.Sum(Range(Cells(2, "LD"), Cells(DerLig, "LD")))
End Sub
Cdlt