In this tutorial you will learn how sum range by cell color with the help of VBA Macro programming in Microsoft Excel
VBA Code in Module:
Function SumByColor(CellReference As Range, SumRange As Range) As Double
For Each cell In SumRange
If cell.Interior.Color = CellReference.Interior.Color Then
SumByColor = SumByColor + cell.Value
End If
Next cell
End Function
VBA Code in Sheet:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("A:Z")) Then
ActiveSheet.Calculate
End If
End Sub