Any formula to count number of cells with a specific color pattern

S

Stu

Is there any formula to count the number of cells (and total the numerical
content of those cells) with a specific color pattern?
 
R

ryguy7272

This function should give you what you want:
Sub countcolor()
Dim rng As Range
Dim cnt As Long

Set rng = Range("A1:E12")
cnt = 0
For Each cell In rng
If cell.Interior.ColorIndex = 3 Then
cnt = cnt + 1
End If
Next
MsgBox cnt
'or Range("K2").Value = cnt
Range("G1").Value = cnt
End Sub

Notice, it is set up to count the number of cells that are colored red:
cell.Interior.ColorIndex = 3

Look here for other Excel color IDs:
http://www.geocities.com/davemcritchie/excel/colors.htm


Regards,
Ryan---
 

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