How to Count Cells by Color in Excel
In this article
Excel has no built-in function that reads a cell's fill color, so the usual way to count by color is to filter the column by color and read the count from the status bar. That works for any color applied manually or by conditional formatting. The exception is when the colors change often and you want the count to update automatically — then you need a helper column or a small macro.
Count by color with a filter
This is the fastest method and needs no formulas. It counts visible rows only, so it works whether the color came from manual formatting or from a conditional formatting rule.
- Select the whole data range, including the header row, or click any cell inside the table and press Ctrl+A once to select the current region.
- Go to the Data tab and click Filter. Drop-down arrows appear on each header.
- Click the arrow on the column that holds the colored cells, point to Filter by Color, and pick the fill color you want to count.
- Look at the status bar at the bottom of the window. It shows the count of visible cells in that column — for example, "Count: 14". If the status bar is hidden, right-click it and tick Count.
- To count a second color, repeat the filter with the next color. Clear the filter (Data > Clear) when you are done so no rows stay hidden.
If the status bar shows nothing, the selected cells may be text rather than numbers. Select the filtered column and the count still appears, because Count works on any cell type. The status bar can also be set to show only Sum or Average; right-click it and enable Count.
Make the count update automatically
A filter count is a snapshot. If rows are recolored, you must filter again. For a count that refreshes on its own, add a helper column that records each cell's color, then count that column with COUNTIF.
Helper column with a color code
- Insert a new column next to the colored data and give it a header such as ColorCode.
- In the first data row of the helper column, type a formula that returns the color index of the cell to its left, for example =CELL("color",A2). Copy it down the column. The numbers returned are color indexes, not RGB values, and they change when the cell is recolored only after the sheet recalculates — press F9 to force it.
- In an empty cell, write =COUNTIF(B2:B100,3) to count all cells whose color index is 3. Replace 3 with the index you saw for your target color.
CELL("color",...) returns 0 for cells with no fill and for cells colored only by conditional formatting, so this method suits manually filled cells. For conditional-formatting colors, count the underlying rule instead: use COUNTIF on the values that trigger the rule.
Macro that counts by fill color
When colors change constantly and a helper column is impractical, a short macro can loop through a range and tally each fill color. Open the Developer tab (File > Options > Customize Ribbon > tick Developer), then Visual Basic, insert a module, and write a function that takes a range and a reference cell and returns the count of cells matching that reference cell's Interior.Color. Run it from a cell like =CountByColor(A2:A100,D1), where D1 holds the color to match. Save the workbook as .xlsm so the macro is kept. Macros are disabled by default in files from other people, so enable them only for workbooks you trust.
Color count reference
| Method | Best for | Updates automatically? | Works with conditional formatting? |
|---|---|---|---|
| Filter by color + status bar | One-off counts, any data size | No | Yes |
| Helper column + COUNTIF | Manual fills that change now and then | Yes, after recalculation | No |
| Macro function | Frequent recoloring, repeated counts | Yes, when the sheet recalculates | No |
Menu labels and the exact position of Filter by Color can differ slightly between Excel versions and between Windows and Mac. The Data > Filter route and the status-bar count are present in all current desktop versions.
What goes wrong and how to fix it
| Symptom | Likely cause | Fix |
|---|---|---|
| Status bar shows no count | Count is switched off in the status bar menu | Right-click the status bar and tick Count |
| Filter by Color is greyed out | No filter applied, or the range has no colored cells | Apply Filter from the Data tab first |
| Helper column returns 0 for every row | Cells are colored by conditional formatting, not fill | Count the rule's values with COUNTIF instead |
| Count includes hidden rows | Using COUNT or COUNTA on the full column | Use SUBTOTAL(3,range) after filtering, or read the status bar |
| Macro gives a different number each run | Colors changed but the sheet has not recalculated | Press F9 before reading the result |
One more trap: two cells can look the same color but hold different fill values, especially after copying from another workbook. If the filter misses cells you expected, select one of them, open the Fill Color palette, and confirm the exact swatch. Reapply the same swatch to the whole group before counting.
Checking the count is right
After filtering, compare the status-bar count with the row numbers you can see: if the last visible row is row 40 and the first is row 2, and every row between is visible, the count should be 39. A quick cross-check is to select the visible cells only (Alt+; on Windows) and read the count again. If the two numbers disagree, a filter on another column is still active — clear all filters and start again.
For a permanent record, copy the filtered range to a new sheet and use COUNTA there; that gives a static number you can compare against later. Keep the original sheet unfiltered so no rows stay hidden by accident.