I came across this user defined function but don’t know how to use it. I placed it in a module in my Personal.xls sheet. I think it counts the cells that have a color but don’t know how to change the code to designate a specific color to count etc…………..Thanks for your help.
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
”””””””””””””””””””
‘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