Try the below UDF. If you are new to macros set the Security level to
low/medium in (Tools|Macro|Security). From workbook launch VBE using
short-key Alt+F11. From menu 'Insert' a module and paste the below
function.Get back to Workbook.
Function GetSumbyColor(varRange As Range, Optional varIDX As Long)
If varIDX = 0 Then varIDX = -4142
For Each cell In varRange
If cell.Interior.ColorIndex = varIDX Then
GetSumbyColor = GetSumbyColor + cell.Value
End If
Next
End Function
Enter the below formula in any cell ;; A1:20 being the range with colored
cells. The below user defined function will give you the sum for cells that
are colored RED.
in cell B1
to return sum of all RED colored cells
=getsumbycolor(A1:A20,3)
to return sum of all cells which are not colored
=getsumbycolor(A1:A5,0)
OR
=getsumbycolor(A1:A5)
Use the color index for more colors
1 = black
2 = white
3 = red
4 = green
5 = blue
6 = yellow
and so on
If this post helps click Yes