Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Counting cells of a specific color

187 views
Skip to first unread message

Blue Max

unread,
Jan 27, 2009, 9:51:16 PM1/27/09
to
Can anyone recommend a good formula for counting the cells of a common color
in a range?

We have a color-coded visual schedule, but need to count the cells of a
common color to determine if we have allocated enough resources to a
particular task. Please note that the assigned colors are related to a
certain task (in a legend) and are often custom colors not chosen directly
from the standard palette.

Pete_UK

unread,
Jan 28, 2009, 4:46:35 AM1/28/09
to
There are no in-built functions to do this.

However, Chip Pearson shows how it can be done with a bit of VBA here:

http://www.cpearson.com/excel/colors.aspx

Hope this helps.

Pete

Gord Dibben

unread,
Jan 28, 2009, 12:36:05 PM1/28/09
to
For counting only...................

Select the range of cells then Edit>Find>Format>Choose from cell>Select a
cell from the custom colors legend>OK

In "Found" dialog hit CTRL + a.

Right-click on Status Bar and "Count"


Gord Dibben MS Excel MVP

Blue Max

unread,
Jan 31, 2009, 1:56:47 PM1/31/09
to
Thank you, Gord, this is an excellent way to get a quick manual count.
However, how do you incorporate this into a cell cell formula in Excel 2007
so that you can maintain a continual dynamic count in a cell on the
worksheet?

Thanks,
Richard

"Gord Dibben" <gorddibbATshawDOTca> wrote in message
news:vk51o49gvupnnqvsp...@4ax.com...

Blue Max

unread,
Jan 31, 2009, 2:44:52 PM1/31/09
to
Thank you, Pete. This was a great recommendation that included additional
color functions that we might find useful down the road. Thank you for
sharing this information with us.

Sincerely,
Richard

************************
"Pete_UK" <pash...@auditel.net> wrote in message
news:b87e2ef1-6206-4cac...@a12g2000pro.googlegroups.com...

Gord Dibben

unread,
Jan 31, 2009, 2:49:24 PM1/31/09
to
You have to use VBA

Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long

Dim rng As Range
Application.Volatile True

For Each rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(rng.Interior.ColorIndex = WhatColorIndex)
End If
Next rng

End Function

Copy/paste the UDF to a general module in your workbook.

Usage is.................=COUNTBYCOLOR(range,3,FALSE)

3 is red

To see a list of colors and index numbers run this macro

Sub ListColorIndexes()
Dim Ndx As Long
Sheets.Add
For Ndx = 1 To 56
Cells(Ndx, 1).Interior.ColorIndex = Ndx
Cells(Ndx, 2).Value = Ndx
Next Ndx
End Sub


Gord

Blue Max

unread,
Jan 31, 2009, 3:20:54 PM1/31/09
to
Thank you, Gord. You may also be interested in the link provided by Pete_UK
in this same thread. If provides some great insight into the color
functions.

Thanks,
Richard

******************


"Gord Dibben" <gorddibbATshawDOTca> wrote in message

news:rs99o4p2u2c21qmr1...@4ax.com...

Pete_UK

unread,
Jan 31, 2009, 4:05:53 PM1/31/09
to
Well, thanks for feeding back, but Chip is the one you should thank
really.

Pete

Gord Dibben

unread,
Jan 31, 2009, 4:56:04 PM1/31/09
to
Thanks


Gord

0 new messages