Excel has no built-in function that sums by color, but the quickest way is to filter by color and use SUBTOTAL. Add =SUBTOTAL(109,B2:B100) above or below your data (changing the range to match your column), select a cell in the data, choose Data > Filter, open the drop-down arrow on the colored column, and pick the color under the filter-by-color option. The formula then totals only the visible, colored cells.
This guide covers four more ways to get the same total: a no-formula check with Find and the status bar, the old GET.CELL trick, a short VBA function you can paste in, and the method that often works best: summing on the rule that made the cells colored in the first place.
Which method should you use?
| Method | Updates when colors change? | Needs a macro-enabled file? | Best for |
|---|---|---|---|
| Filter by Color + SUBTOTAL | Yes, when you reapply the filter | No | Most people; one color at a time |
| Find (Format) + status bar | No, it’s a one-off check | No | A quick total without formulas (Windows) |
| GET.CELL named formula | Only after recalculating | Yes (.xlsm) | Older files and setups that allow Excel 4.0 macros |
| VBA SumByColor function | Only after recalculating | Yes (.xlsm or add-in) | Totals for several colors side by side |
| SUMIF/SUMIFS on the rule | Yes, automatically | No | Colors from conditional formatting or a status |
Method 1: Filter by Color and SUBTOTAL
The SUBTOTAL function ignores rows that a filter hides, so once you filter to one color, it adds up only those cells.
- Make sure your data has a header row and no completely blank rows in the middle.
- In a cell above or below the data, type
=SUBTOTAL(109,B2:B100), replacing B2:B100 with the cells you want to add. Putting it above the header means a filter can’t hide the result. - Select any cell in the data and choose Data > Filter, as in Microsoft’s guide to filtering data in a range or table. If your data is formatted as a table, the filter arrows are already there.
- Select the arrow in the header of the colored column.
- Point to Filter by Color and choose the fill color you want. The submenu may separate cell colors from font colors.

The SUBTOTAL result now shows the sum of the colored cells. To total a different color, change the filter. To see everything again, open the arrow and clear the filter.
Why 109 and not 9?
Microsoft’s SUBTOTAL page explains that function numbers 1 to 11 include rows you hide manually, while 101 to 111 exclude them. Filtered-out rows are always excluded with either number. Use 109 so a row you hid by hand doesn’t sneak into your total. A plain =SUM(B2:B100) doesn’t work here because it adds every cell, visible or not.
To count the colored cells instead, use =SUBTOTAL(103,B2:B100) to count non-empty visible cells, or 102 to count only visible numbers. If rows seem to be missing when you’re done, see how to unhide all rows in Excel.
The downside: you get one color’s total at a time, and the total only changes when you reapply the filter after recoloring cells.
Method 2: Find by format and read the status bar
If you just need the number and don’t want a formula, Excel’s Find tool can select every cell with a given fill. This works in Excel for Windows; Microsoft’s Mac instructions don’t include the Format option.
- Select the range to search, or a single cell to search the whole sheet.
- Press Ctrl + F, or choose Home > Find & Select > Find.
- Select Options>>, leave Find what empty, and select Format.
- In the Find Format box, select Choose Format From Cell, then click one of the colored cells.
- Select Find All. The list at the bottom shows every matching cell.
- Click in that list and press Ctrl + A to select all the results, then close the dialog.
With the cells selected, look at the status bar at the bottom of the Excel window. It typically shows Sum, Average and Count for the selection. If Sum isn’t there, right-click the status bar and tick it. These steps follow Microsoft’s guide to finding text and numbers on a worksheet; the Ctrl + A and status bar steps may look slightly different in your version.
Choose Format From Cell copies all of that cell’s formatting, including number format and font. If some colored cells are missed, select Format again and set only the fill color on the Fill tab.
Method 3: GET.CELL with a helper column
GET.CELL is a legacy Excel 4.0 macro function. You can’t type it straight into a cell, but you can use it inside a defined name to read each cell’s fill color as a number, then sum on that number.
- Click cell C2, next to the first value in column B. (Adjust the letters to your sheet.)
- Choose Formulas > Define Name.
- Enter the name FillColor, and in Refers to type
=GET.CELL(38,Sheet1!B2), using your sheet name and no dollar signs. Select OK. - In C2, type
=FillColorand copy it down the column. Each cell shows a number for the fill color beside it. - Find the number for the color you want (say it’s 6), then total it with
=SUMIF(C2:C100,6,B2:B100).
Things to know before you rely on it:
- Save as .xlsm. A regular .xlsx file can’t keep the named formula working, so choose Excel Macro-Enabled Workbook when you save.
- Macro settings. Microsoft’s page on working with Excel 4.0 macros says Excel still supports them but encourages moving to VBA. If the helper column shows an error, check File > Options > Trust Center > Trust Center Settings > Macro Settings for Enable Excel 4.0 macros when VBA macros are enabled. In Microsoft 365, the cells may show #BLOCKED! until that setting allows it.
- No automatic update. Changing a fill color doesn’t recalculate the helper column. Press Ctrl + Alt + F9 to force a full recalculation.
- Similar shades. The color numbers come from a limited palette, so two close shades can return the same number.
- Not in Excel for the web. Microsoft says workbooks that use Excel 4.0 macro functions can’t be displayed in a browser window.
Method 4: A VBA SumByColor function
A custom function gives you a formula like =SumByColor(B2:B100,E2) that adds every cell in B2:B100 with the same fill as E2. Put a sample of each color in column E and you can total several colors side by side.

- Press Alt + F11 to open the Visual Basic Editor.
- Choose Insert > Module.
- Paste this code:
Function SumByColor(SumRange As Range, ColorCell As Range) As Double
' Adds the numbers in SumRange whose fill matches ColorCell.
Application.Volatile
Dim c As Range
Dim total As Double
For Each c In SumRange.Cells
If c.Interior.Color = ColorCell.Interior.Color Then
If VarType(c.Value2) = vbDouble Then
total = total + c.Value2
End If
End If
Next c
SumByColor = total
End Function
- Close the editor and type
=SumByColor(B2:B100,E2)in any cell. - Save the workbook as an Excel Macro-Enabled Workbook (.xlsm).
The total is declared As Double so decimals aren’t dropped, which is a common bug in versions that use Long. To count colored cells instead, copy the function, rename it CountByColor, and change total = total + c.Value2 to total = total + 1. To match font color, change both Interior.Color parts to Font.Color.
Microsoft’s guide to creating custom functions in Excel covers the basics, including saving the function as an Excel Add-In (.xlam) so it’s available in every workbook. Keep in mind:
- Recoloring a cell doesn’t trigger a recalculation. Press F9 (or Ctrl + Alt + F9) after changing colors.
Application.Volatilemakes the function recalculate whenever Excel recalculates. - If you see #NAME?, the workbook or add-in that holds the function isn’t open, or macros are disabled.
- If Excel blocks macros in a file you downloaded, right-click the file, choose Properties, tick Unblock on the General tab and select OK, as Microsoft explains in A potentially dangerous macro has been blocked. Only do this for files you trust.
- Microsoft notes that in Excel for the web, a .xlsm file opens but macros don’t run in a browser window, so the function only works in the desktop app.
Method 5: Sum on the rule behind the color
Colors usually mean something: overdue, over budget, region North. If they come from a rule, sum on that rule directly. The result updates by itself, works in any version of Excel, and doesn’t need macros. Use SUMIFS, whose criteria can be numbers, expressions, cell references or text:
- Cells turn green when a value is over 1,000:
=SUMIF(B2:B100,">1000") - Rows are colored when column C says Paid:
=SUMIFS(B2:B100,C2:C100,"Paid") - Two conditions, such as Paid and region North:
=SUMIFS(B2:B100,C2:C100,"Paid",D2:D100,"North")
If you color cells by hand, consider adding a status column with the reason for the color. Then you can use SUMIFS, sort and filter on it, and even drive the color from it with conditional formatting.
What about conditional formatting colors?
GET.CELL and the SumByColor function read the fill you applied, not the color conditional formatting displays. Microsoft’s Range.DisplayFormat documentation says DisplayFormat is affected by conditional formatting, but it doesn’t work in user-defined functions and returns #VALUE! there. It does work in a macro. This one sums the selected cells that display the same color as the active cell:
Sub SumSelectionByDisplayedColor()
Dim c As Range
Dim total As Double
Dim target As Long
target = ActiveCell.DisplayFormat.Interior.Color
For Each c In Selection.Cells
If c.DisplayFormat.Interior.Color = target Then
If VarType(c.Value2) = vbDouble Then total = total + c.Value2
End If
Next c
MsgBox "Total: " & total
End Sub
Paste the macro into a module the same way as the function above (Alt + F11, Insert > Module), and save as .xlsm. Select the range by dragging from a colored cell, so that cell is the active one (or press Enter to move the active cell within the selection), then run the macro from View > Macros (or press Alt + F8). Still, summing on the rule itself with SUMIFS is simpler and always up to date.
Common problems
- The SUBTOTAL result didn’t change after filtering. Check that the formula range covers all the data rows and that the formula isn’t inside the filtered range, where it could be hidden.
- The total includes hidden rows. You used function number 9. Change it to 109.
- Colors that look the same don’t match. Two shades can differ slightly. Recolor the cells from the same swatch, or use Choose Format From Cell.
- The function total is stale. Press F9 or Ctrl + Alt + F9 after recoloring.
- Numbers stored as text are skipped. SUBTOTAL and SUMIFS ignore text. Convert them to numbers first.
For grouped data, Excel’s outline tools can also show totals per group; see how to collapse an outline to show only subtotals.
Questions
Is there a SUMIF by color formula in Excel?
No. SUMIF and SUMIFS criteria are values, expressions or text, not formats. Filter by color with SUBTOTAL, use a VBA function, or sum on the condition behind the color.
Can I sum by color in Excel for the web?
SUMIFS works the same in the browser, and you can filter there too, though filter options can differ from the desktop app. VBA functions and GET.CELL don’t, because macros don’t run there.
How do I count colored cells instead of summing them?
Filter by color and use =SUBTOTAL(103,B2:B100), or use the CountByColor version of the VBA function above.
Matt Williams is the writer and editor behind TechInfoHome. He holds a degree in computer science and has more than 10 years of experience working in IT. For the past 5 years he has written online tutorials for Windows, Microsoft Office, Google apps and iPhone, with a focus on clear steps that get readers to a working fix quickly.