Sub CompterCellulesEnvert()
Dim PlageTest As Range, iCell As Range
Set PlageTest = Range("A2:C24")
For Each iCell In PlageTest
If iCell.Interior.color = RGB(146, 208, 80) Then
CompterCellules = CompterCellules + 1
End If
Next iCell
MsgBox "Il y a " & CompterCellules & " cellules vert."
[G28].Value = CompterCellules
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim PlageTest As Range, iCell As Range
Set PlageTest = Range("A2:C24")
For Each iCell In PlageTest
If iCell.Interior.Color = RGB(146, 208, 80) Then
CompterCellules = CompterCellules + 1
End If
Next iCell
MsgBox "Il y a " & CompterCellules & " cellules vert."
[G28].Value = CompterCellules
End Sub
Sub CompterCellulesEnvert()
Dim PlageTest As Range, iCell As Range
With ActiveWorkbook
Set PlageTest = Range("A2:C24")
For Each iCell In PlageTest
If iCell.Interior.color = RGB(146, 208, 80) Then
CompterCellules = CompterCellules + 1
End If
Next iCell
MsgBox "Il y a " & CompterCellules & " cellules vert."
[G28].Value = CompterCellules
Wnd With
End Sub
=CountColoredCells(A2:D24;E28)
Function CountColoredCells(rng As Range, color As Range) As Long
Dim cell As Range
Dim count As Long
count = 0
For Each cell In rng
If cell.Interior.color = color.Interior.color Then
count = count + 1
End If
Next cell
CountColoredCells = count
End Function