How to Sum Range By Cell Color in Microsoft Excel | Learn In 5 Minutes | VBA Macro Programming

Опубликовано: 30 Март 2026
на канале: Learn In 5 Minutes
1,001
5

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