FormulaCraft

How to sum cells by color in Excel and Google Sheets

Topic:SUM & aggregation
Excel & Google Sheets
=SUMIF(B2:B5,"Red",C2:C5)

Verified example

Computed by a real spreadsheet engine on the sample data below.

ItemColor LabelAmount
AppleRed100
BlueberryBlue200
StrawberryRed150
GrapeBlue180

=SUMIF(B2:B5,"Red",C2:C5)250

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Add a helper column (e.g. column B) next to the colored values column. Type a color label — "Red", "Blue", "Green" — in each row to mirror the fill colors applied.
  2. 2In an empty cell enter =SUMIF(B2:B5,"Red",C2:C5) to sum column C values where the helper column equals "Red".
  3. 3Press Enter. Repeat with different criteria for each color you need: =SUMIF(B2:B5,"Blue",C2:C5), etc.
  4. 4Excel VBA alternative: open the VBA editor (Alt+F11), Insert → Module, define `Function SumByColor(colorCell As Range, rng As Range) As Double` that loops checking `cell.Interior.Color = colorCell.Interior.Color`. Save as .xlsm. Use as =SumByColor($A$1, C2:C5) where A1 is a sample cell with the target color.
  5. 5Google Sheets Apps Script alternative: Extensions → Apps Script, paste a custom function using SpreadsheetApp.getActiveSheet().getRange(...).getBackgrounds(). Use as =SumByColor(C2:C5, "#FF0000").

Tips

Working on a sheet you inherited? Run the Auditor on the whole file first — it flags every #REF!, #N/A, broken column pattern, and inconsistent formula in seconds, free, no signup.

Frequently asked

Is there a native SUMBYCOLOR function in Excel or Sheets?

No. Neither application exposes cell fill color to worksheet formulas natively, even in Excel 365 / 2024. You must use a helper column, VBA macro, or Google Apps Script.

Will a VBA sum-by-color function work in Google Sheets?

No — VBA is Excel-only. Sheets uses Apps Script (JavaScript-based). The equivalent: Extensions → Apps Script → write a custom function that uses range.getBackgrounds() to read the color hex, then sum matching cells.

Why doesn't my SumByColor function update when I change a cell color?

Color changes don't trigger a recalculation. Either force a recalc (F9 in Excel, Ctrl+Shift+F9 in Sheets) after recoloring, or add a volatile reference like `+NOW()*0` to the formula so it re-evaluates on every workbook change (warning: degrades performance on large sheets).

Can I sum by color from conditional formatting rules?

Not directly. Macros read the underlying fill color, which conditional formatting doesn't change. Use the conditional rule's logic in SUMIF instead — e.g. if the rule highlights cells > 100, use =SUMIF(C2:C100,">100",C2:C100).

How do I sum based on font color instead of fill color?

Same approach with a different VBA property: replace Interior.Color with Font.Color in the macro. The helper-column approach works identically — tag rows by category and SUMIF.

What's the simplest one-time approach without formulas?

Apply Filter → Filter by Color to the value column, then look at the Sum in the status bar (Excel) or use =SUBTOTAL(9, range) which respects the filter. Fast for ad-hoc analysis; doesn't update when you change filters.

More on SUM & aggregation

See all →

Formulas used

Related tasks

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: