It's not reccomended to do it as there are lots of problems with it, if possible its better to test for the value rather than colour, there's a reason excel doesnt provide this function!!!
these two functions should help if you REALLY have to!!!
Create a new module, and paste the code in the module
then in your sheet :
=SumCellColor(A1,A1:A99) where A1 is a cell of the color you want to sum!
here is code to count cells of a colour :
Function CountCellColor(ColorToTest As Range, MyRange As Range) As Long
Dim mycell As Range
Dim Count As Long
Count = 0
testcolor = ColorToTest.Interior.ColorIndex
For Each mycell In MyRange
With mycell
If mycell.Interior.ColorIndex = testcolor Then
Count = Count + 1
End If
End With
Next
CountCellColor = Count
End Function
here is code to sum cells of a colour
Function SumCellColor(ColorToTest As Range, MyRange As Range) As Double
Dim mycell As Range
Dim Total as Double
testcolor = ColorToTest.Interior.ColorIndex
For Each mycell In MyRange
With mycell
If mycell.Interior.ColorIndex = testcolor Then
Total=Total+mycell.value
End If
End With
Next
SumCellColor = Total
End Function
Bookmarks