Anbuselvam K
Member
Hi
In the attached sheet sum by colour is not working or not giving proper results by using the below VBA Code
Example in cells BS6 and BR33 sum value should be 100 but there is 99
Likewise many cells different values are there.
Can anyone check and correct the code or guide me on what's the problem if the code is correct?
Thanks in advance.
In the attached sheet sum by colour is not working or not giving proper results by using the below VBA Code
Example in cells BS6 and BR33 sum value should be 100 but there is 99
Likewise many cells different values are there.
Can anyone check and correct the code or guide me on what's the problem if the code is correct?
Thanks in advance.
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