Calculate number of cells colored red

Closed
Spense - 28 Oct 2009 à 19:19
venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 - 28 Oct 2009 à 21:37
Hello,
Can someone help me calculate a formula to calculate number of cells that are a certain color?

Thanks,

1 response

venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 811
28 Oct 2009 à 21:37
try this macro

Sub test()
Dim r As Range, c As Range, j As Integer, m As Integer
Set r = Range(Range("A1"), Range("A1").End(xlDown))
For Each c In r
If c.Interior.ColorIndex <> -4142 Then
j = c.Interior.ColorIndex
MsgBox j
GoTo exitloop
End If
Next c
exitloop:
m = 0
For Each c In r
If c.Interior.ColorIndex = j Then m = m + 1
Next c
MsgBox "count of cell in color " & j & "  is   " & m
End Sub