Cell Color Count with a condition

Closed
Manu - 2 Apr 2017 à 08:53
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 3 Apr 2017 à 11:39
Hello,

I need a help.

I need to count cells in a range having a specific color (In one column) & cells in a range having a text (In another column).

I have already used VBA code for counting colored cells seperately. But I'm not getting correct

I'm desperately in need of help.

Related:

1 response

TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 555
3 Apr 2017 à 11:39
Hi manu,

You didn't provide any specifics, but use the following code to count the number of yellow cells in the range A1:A10:
Sub RunMe()
Dim x As Integer
For Each cell In Range("A1:A10")
    If cell.Interior.Color = 65535 Then
        x = x + 1
    End If
Next cell
MsgBox "There are " & x & " yellow cells."
End Sub


Use the macro recorder to find the color code for other colors.

To count cell with specific text, you can use a formula:
=COUNTIF(B1:B10;"MyText")

Best regards,
Trowa