View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Loretta Loretta is offline
external usenet poster
 
Posts: 13
Default Counting cells with colored font

This worked for me, just select a fixed cell and color code it so it knows
what color to refer to in the function. Add this macro to your visual basic..

Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As
Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult

''''''''''''''''''''''''''''''''''''''
'Written by Ozgrid Business Applications
'www.ozgrid.com

'Sums or counts cells based on a specified fill color.
'''''''''''''''''''''''''''''''''''''''

lCol = rColor.Interior.ColorIndex

If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If

ColorFunction = vResult
End Function
--
Thanks!
Loretta


"JockW" wrote:

Hi,I know this can be done with Excel 2003 onwards, but I've got 2002 and I
can't find a way to count the cells in a range which have blue font and which
ones have red font.
Any ideas?
Range is C5:E17
--
tia