SOLVED

countif a cell is a specific color shade

Copper Contributor

Soliciting help on counting a cell given a specific color shade.

 

I was going to use (the range is an example): COUNT IF (A1:A10, cell("color",[ --- ])) ... but where do I find a defined color pallet ID #?

3 Replies
best response confirmed by Grahmfs13 (Microsoft)
Solution

@KennyMikus 

You need a custom VBA function for this. Here is a simple example:

Function CountIfColor(CountRange As Range, ColorCell As Range) As Double
    Dim ACell As Range
    Dim TheColor As Long
    Application.Volatile
    TheColor = ColorCell.Interior.Color
    For Each ACell In CountRange
        If ACell.Interior.Color = TheColor Then
            CountIfColor = CountIfColor + 1
        End If
    Next ACell
End Function

Let's say you want to count the number of cells in A1:D10 that have the same fill color as K1.

The formula would be

=CountIfColor(A1:D10,K1)

Thank you!
Worked like a champ! Thanks Again and I learned something ... I can code in EXCEL!
1 best response

Accepted Solutions
best response confirmed by Grahmfs13 (Microsoft)
Solution

@KennyMikus 

You need a custom VBA function for this. Here is a simple example:

Function CountIfColor(CountRange As Range, ColorCell As Range) As Double
    Dim ACell As Range
    Dim TheColor As Long
    Application.Volatile
    TheColor = ColorCell.Interior.Color
    For Each ACell In CountRange
        If ACell.Interior.Color = TheColor Then
            CountIfColor = CountIfColor + 1
        End If
    Next ACell
End Function

Let's say you want to count the number of cells in A1:D10 that have the same fill color as K1.

The formula would be

=CountIfColor(A1:D10,K1)

View solution in original post