Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting cells by color

Status
Not open for further replies.

wwgmr

MIS
Mar 12, 2001
174
US
Hi all question

I have formula that counts cells by their color, my problem is it doesn't count the cell if you enter any numbers into the cell first and then fill the cells color. I can't understand why?

Here is the code.

Function CountColor(rColor As Range, rSumRange As Range)

''''''''''''''''''''''''''''''''''''''
'Counts cells based on a specified fill color.
'''''''''''''''''''''''''''''''''''''''
Dim rCell As Range
Dim iCol As Integer
Dim vResult

iCol = rColor.Interior.ColorIndex

For Each rCell In rSumRange
If rCell.Interior.ColorIndex = iCol Then
vResult = vResult + 1
End If
Next rCell

CountColor = vResult
End Function


Is there a better way to write it so that it doesn't matter if you put in number first then fill in cell color? I am using a conditional format for the cells if they are blank and so I cannot fill a color till I have data in the cell.

Any help would be great, I am confused as to why having this problem.

Eric
 
Hi,

If you are using Conditional Formatting to color the cells, then use the SAME criteria in your CountColor.

In fact...

you could probably do it with a spreadsheet countif formula.

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top