2 ways to Sum Cells Based on Their Color in Excel using VBA & SUBTOTAL Function

2 ways to Sum Cells Based on Their Color in Excel using VBA & SUBTOTAL Function

Unlock the power of Excel with this tutorial on summing cells based on their color using two different methods - a custom VBA function and the SUBTOTAL function. Learn how to write and implement VBA code for a custom function, and dynamically calculate sums based on cell colors. Discover the alternative approach using the SUBTOTAL function, which adapts to filtered subsets of data. Improve your Excel skills and make your data analysis more efficient! Subscribe for more Excel tips and tricks! #excel #exceltips #exceltutorial #vbaprogramming #vba Used Code: Function SumCellsByColor(CellRange As Range, CellColor As Range) As Double ' Declare variables Dim CellColorValue As Long Dim RunningSum As Double ' Get the RGB color value of the target cell CellColorValue = CellColor.Interior.Color ' Loop through each cell in the specified range For Each i In CellRange ' Check if the current cell has the same background color as the target color If i.Interior.Color = CellColorValue Then ' If true, add the cell's value to the running sum RunningSum = RunningSum + i.Value End If Next i ' Set the function's return value to the calculated sum SumCellsByColor = RunningSum End Function —————————————————————————————— 📫 Business inquiries: [email protected] ——————————————————————————————