How can I count the number of cells with a particular color/shade

L

Lynn

I have a spreadsheet where I need to count the number cells with each of
these colors/shades: Yellow, Orange, and Red

Thanks, Lynn
 
J

Joel

You need a UDF function like the one below

Function CountColors(Target As Range, CellColor As String)
Select Case CellColor
Case "Yellow"
SearchColor = 6
Case "Red"
SearchColor = 3
Case "Orange"
SearchColor = 9
End Select

CountColors = 0
For Each cell In Target
If Range("A1").Interior.ColorIndex = SearchColor Then
CountColors = CountColors + 1
End If
End If
End Function
 
J

Joel

I made a small typo

Function CountColors(Target As Range, CellColor As String)
Select Case CellColor
Case "Yellow"
SearchColor = 6
Case "Red"
SearchColor = 3
Case "Orange"
SearchColor = 9
End Select

CountColors = 0
For Each cell In Target
If Range("A1").Interior.ColorIndex = SearchColor Then
CountColors = CountColors + 1
End If
Next cell
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top