# Thread: RESOLVED: Count or Sum Macro Question (Excel 2003)

1. ## Re: RESOLVED

Nevermind...I found it...I just had to rewrite the formula as Ozgrid explained further in his directives:

=ColorFunction(C1,\$A\$1:\$A\$12,TRUE)

Making the Boolean statement True instead of False, or empty

2. ## RESOLVED: Count or Sum Macro Question (Excel 2003)

I have some code as follows I am using from the Ozgrid site: (My question is: It seems to count the cells that have color, but does not sum them. What would have to be tweaked to sum them as SUM is already being used in the code, I'm confused.)

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

''''''''''''''''''''''''''''''''''''''
'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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•