View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
David David is offline
external usenet poster
 
Posts: 1,560
Default Is there a way to count cells in a range with a given backcolo

Thanks, FSt1. Good name!

I knew how to do this by macro. There is a way (I read an article some time
ago) of using a function, like "=if(interiorcolor=green, "Yes", "No"). It
can be done, I just can't remember how.




"FSt1" wrote:

hi
Sub countcolor()
Dim rng As Range
Dim cnt As Long

Set rng = Range("A2:I30")
cnt = 0

For Each cell In rng
If cell.Interior.ColorIndex = 40 Then
cnt = cnt + 1
End If
Next
MsgBox cnt
'or Range("K2").Value = cnt

End Sub

see this site for color indexes...
http://www.mvps.org/dmcritchie/excel/colors.htm

regards
FSt1

"David" wrote:

Is there a function to count the cells in a range, which have a given
interior color?