Yesterday I found this UDF designed to sum only the cell that match a specific background color.
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
For some reason it's rounding the result instead of giving a true sum. I assume it has something to do with the line "Dim ColIndex As Integer" but I am clueless about how to read this code. Other than the rounding it works great, can someone please tell me what to change so that it provides the real sum and not a rounded integer?
Bookmarks