You are on page 1of 1

Function SumColor(DefClr As Range, DefRng As Range)

Dim MyCell As Range


Dim MyCol As Long
Dim SumColCell

'Identify the colored cell


MyCol = DefClr.Interior.ColorIndex

'Sum the colored cells in the range


For Each MyCell In DefRng
If MyCell.Interior.ColorIndex = MyCol Then
SumColCell = WorksheetFunction.SUM(MyCell, SumColCell)
End If
Next MyCell

SumColor = SumColCell

End Function

You might also like