I need to sum the values of a range by the background color of the cell. So I created 2 UDFs. The first one that creates the color index works fine:
The Second UDF works fine as long as we're summing whole numbers, but will not sum decimals. My suspicion is partly due to line 3 "As Integer", but I changed that to
Single, Double, Long. No change. A cell entry of 0.5 returns a "0" and 1.5 returns "2". I only need to be as precise as 1 decimal (tenths) place.
I appreciate any assistance.
VBA Code:
Function ColorIndex(CellColor As Range)
ColorIndex = CellColor.Interior.ColorIndex
End Function
The Second UDF works fine as long as we're summing whole numbers, but will not sum decimals. My suspicion is partly due to line 3 "As Integer", but I changed that to
Single, Double, Long. No change. A cell entry of 0.5 returns a "0" and 1.5 returns "2". I only need to be as precise as 1 decimal (tenths) place.
VBA Code:
Function SumByColor(CellColor As Range, rRange As Range)
Dim cSum As Long
Dim ColIndex As Integer
ColIndex = CellColor.Interior.ColorIndex
For Each cl In rRange
If cl.Interior.ColorIndex = ColIndex Then
cSum = WorksheetFunction.Sum(cl, cSum)
End If
Next cl
SumByColor = cSum
End Function
I appreciate any assistance.