UDF: Sum By Colour

This UDF allows you to sum a range by specifying the colour of the cell you want to sum.

[responsive]Sum by Colour Demonstration
[/responsive]


Function SumByColour(CellColour As Range, SumRange As Range)

Application.Volatile

Dim cTotal As Long
Dim ColIndex As Integer
Dim c As Range

'THIS IS THE COLOUR OF THE CELL CHOSEN
ColIndex = CellColour.Interior.ColorIndex

For Each c In SumRange

If c.Interior.ColorIndex = ColIndex Then

'ADD THE TOTAL OF THE SUMS TOGETHER
cTotal = cTotal + c.Value

End If

Next c

SumByColour = cTotal

End Function