Function colorsum(y As Range, rng, z As Integer)
Application.Volatile
Dim c As Double
Dim x As Range
colorsum = 0
For Each x In rng
If x.Interior.ColorIndex = y.Interior.ColorIndex Then
c = x.Offset(0, z).Value
Else
c = 0
End If
colorsum = colorsum + c
Next x