How to Count Highlighted Cells in Excel (4 Ways)

Last updated on November 10th, 2026 at 10:08 am

Excel has no function that counts cells by fill color, so on Windows use Find: select the range, press Ctrl + F, click Options >>, open the Format arrow, pick Choose Format From Cell, click a highlighted cell, then click Find All. The total, such as “12 cell(s) found,” shows at the bottom, as in Microsoft’s guide to finding formats. Colors from conditional formatting need COUNTIF on the rule’s condition instead.

Pick a method

What you needBest methodMacros needed?
A quick one-time numberFind AllNo
A count that changes when you switch colorsFilter by Color + SUBTOTALNo
A formula you can copy for several colorsCountColor VBA functionYes (.xlsm)
A color code for every row, no code to pasteGET.CELL helper columnYes (Excel 4.0 macro function)
Colors added by a conditional formatting ruleCOUNTIF on the rule’s conditionNo

Before you start: which kind of highlight is it?

Excel can color a cell in two ways, and they behave differently when you count.

  • Manual fill: someone selected the cell and used Home > Fill Color. Every method in this guide can see it.
  • Conditional formatting: a rule colors the cell automatically, for example “fill yellow when the due date has passed.” Find and a VBA function read the cell’s own fill, not the color a rule paints on top, so use the conditional formatting section instead.

To check, click a highlighted cell and select Home > Conditional Formatting > Manage Rules. If the list shows a rule that applies to that cell, the color comes from the rule.

Also watch for look-alike shades: two yellows that look identical can be different colors to Excel, which is why the steps below sample an actual highlighted cell.

Method 1: Count with Find All

The example below uses a task list in A1:D200 where overdue tasks for Alex, Jordan and Priya are filled yellow.

  1. Select the range you want to count, such as A2:D200. If you select only one cell, Excel searches the whole sheet.
  2. Press Ctrl + F (or go to Home > Find & Select > Find), then click Options >> to expand the dialog.
  3. Click the small arrow on the right side of the Format button and choose Choose Format From Cell. The pointer turns into an eyedropper.
Excel Find and Replace dialog with Options expanded and the Format menu open showing Choose Format From Cell
In the expanded Find dialog, open the Format arrow and choose Choose Format From Cell. This example colors only 14 Task cells yellow, rather than filling all four cells in each row.
  1. Click one of the yellow cells. The Preview box next to Format now shows that fill.
  2. Leave Find what empty and click Find All.

The bottom-left corner of the dialog shows the count, such as “14 cell(s) found,” and the list above it shows the address of each match. Press Ctrl + A with the list active to select every found cell; the status bar then shows Count, and for numbers, Sum and Average of just those cells. For counts that do not depend on color, such as filled, numeric or empty cells, see how to count the number of cells in Excel.

Find and Replace results list with the message 14 cells found at the bottom left
With Find what empty, Find All lists the 14 yellow Task cells. Their addresses match the same 14 records counted by the filter example.

Choose Format From Cell copies everything about the sample cell, including font, borders and number format. If some yellow cells are missing from the results, click Format itself (not the arrow), select Clear, and set only the color on the Fill tab.

When you’re done, open the Format arrow and select Clear Find Format. Otherwise your next ordinary search will quietly look only for yellow cells.

Method 2: Filter by Color and SUBTOTAL

This gives you a formula on the sheet that updates every time you change the filter.

  1. Click any cell in your data and press Ctrl + Shift + L (or select Data > Filter). Arrows appear in the header row.
  2. In an empty cell above or below the data, type =SUBTOTAL(103,A2:A200). Before filtering, it shows the number of non-empty cells in the range.
  3. Click the arrow on the colored column, point to Filter by Color, and pick the yellow swatch under Filter by Cell Color.
Excel column filter menu with Filter by Color expanded and the yellow cell color selected
Open the Task filter, point to Filter by Color, then choose the yellow cell-color swatch. Before filtering, the count in F1 is 199; the example uses A2:A200 without moving the header.

Only the highlighted rows stay visible, and the formula now shows how many there are. Pick a different color in the same menu to count that color instead. Microsoft’s page on filtering by color confirms the menu works for manual fills, cell styles and conditional formatting colors.

Filtered Excel sheet with only yellow rows visible and a SUBTOTAL formula showing 14
After filtering yellow Task cells, F1 shows 14 from =SUBTOTAL(103,A2:A200). The original row numbers and the status bar confirm that 14 of the 199 task records remain visible.

A few details make the formula reliable:

  • 103 vs. 3: both count non-empty visible cells after filtering. 103 also skips rows you hid with Hide, so it’s the safer choice. Per the SUBTOTAL function reference, 102 or 2 counts only numbers.
  • Pick a column that’s never blank, such as a task name or ID. SUBTOTAL skips empty cells, so a highlighted row with an empty cell in the counted column isn’t counted.
  • Sum the same rows with =SUBTOTAL(109,C2:C200) to total a number column for the highlighted rows.
  • Using a table? Turn on Table Design > Total Row and set the total to Count. Excel writes the SUBTOTAL formula for you.

The same visible-rows trick is handy whenever you count the number of rows in Excel after filtering.

Method 3: A CountColor VBA function

If you want an ordinary-looking formula such as =CountColor(A2:A200,F2), which counts cells in A2:A200 that match the fill of F2, add this short function. The workbook has to be saved as a macro-enabled file (.xlsm), and anyone who opens it must allow macros. If Excel shows a security bar, see how to enable macros in Excel for Microsoft 365 safely.

  1. Press Alt + F11 to open the Visual Basic Editor.
  2. Choose Insert > Module. A blank code window opens.
  3. Paste the code below, then close the editor.
Function CountColor(rng As Range, sample As Range) As Long
    Dim c As Range
    Application.Volatile
    For Each c In rng
        If c.Interior.Color = sample.Interior.Color Then
            CountColor = CountColor + 1
        End If
    Next c
End Function
  1. Fill a spare cell, such as F2, with the color you want to count (or point to an existing highlighted cell).
  2. In another cell, type =CountColor(A2:A200,F2) and press Enter.
  3. Select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). Saving as a regular .xlsx removes the code.

To count several colors at once, build a small legend: fill F2, F3 and F4 with yellow, green and red, type =CountColor($A$2:$A$200,F2) in G2, and copy it down. Unlike Find, this function also counts empty cells that have a fill.

Changing a fill color doesn’t make Excel recalculate, so press F9 after recoloring cells. Application.Volatile makes the function update on every recalculation, which can slow a large workbook, so keep the range to the rows you actually use rather than a whole column.

To add up the values in colored cells instead of counting them, paste this second function into the same module and use =SumColor(C2:C200,F2):

Function SumColor(rng As Range, sample As Range) As Double
    Dim c As Range
    Application.Volatile
    For Each c In rng
        If c.Interior.Color = sample.Interior.Color Then
            If IsNumeric(c.Value) Then SumColor = SumColor + c.Value
        End If
    Next c
End Function

Method 4: A GET.CELL helper column

GET.CELL is an old Excel 4.0 macro function. It can’t be typed straight into a cell, but it works inside a defined name and returns a color number for each row. You don’t paste any code, though the file still needs to be saved as .xlsm.

  1. Click B2, the first cell of an empty column next to the colored cells in column A.
  2. Select Formulas > Define Name. In Name, type FillCode.
  3. In Refers to, enter =GET.CELL(38,Sheet1!A2), using your sheet’s name, with no dollar signs so the reference moves with each row. Click OK.
  4. In B2, type =FillCode and fill it down to the last row. Unfilled cells return 0; highlighted cells return a number such as 6.
  5. Count one color with =COUNTIF(B2:B200,6), or point at a sample row’s code, as in =COUNTIF(B2:B200,B5).

Things to know before you rely on it:

  • The codes don’t refresh when you recolor a cell. Press Ctrl + Alt + F9 to force a full recalculation.
  • The number comes from Excel’s older 56-color palette, so two similar custom shades may get the same code.
  • If the helper column returns an error or Excel warns that Excel 4.0 macros are disabled, check File > Options > Trust Center > Trust Center Settings > Macro Settings. Microsoft’s Excel 4.0 macro page describes the Enable Excel 4.0 macros when VBA macros are enabled option. Only turn it on for files you trust.

When the color comes from conditional formatting

Find and the CountColor function read the fill stored in the cell, so they don’t see colors a rule applies. You have three good options:

  • Count the rule’s condition. If the rule fills cells over 100, use =COUNTIF(C2:C200,">100"). If it highlights text containing “overdue,” use =COUNTIF(D2:D200,"*overdue*"). For two conditions, such as overdue tasks owned by Jordan, use =COUNTIFS(D2:D200,"*overdue*",B2:B200,"Jordan"). This count updates by itself and is the most dependable route. The COUNTIF guide has more criteria examples.
  • Filter by Color. Method 2 works with rule colors, so filter and read the SUBTOTAL result.
  • Run a one-off macro. VBA’s DisplayFormat reads the color you actually see, but Microsoft notes it doesn’t work in a worksheet function (it returns #VALUE!). It does work in a macro you run. Paste this into a module, select the range starting from a highlighted cell, then press Alt + F8 and run it:
Sub CountDisplayedColor()
    Dim c As Range, n As Long, target As Long
    target = ActiveCell.DisplayFormat.Interior.Color
    For Each c In Selection
        If c.DisplayFormat.Interior.Color = target Then n = n + 1
    Next c
    MsgBox n & " cell(s) match the active cell's color."
End Sub

To build or review the rules themselves, see how to use conditional formatting in Excel.

Excel for Mac and Excel for the web

  • Excel for Mac: Microsoft’s Find instructions for Mac list no Format option, so use Filter by Color with SUBTOTAL, or the CountColor function. To reach the code editor, turn on the Developer tab and select Visual Basic; the guide to enabling macros in Excel on Mac shows where that setting lives.
  • Excel for the web: SUBTOTAL and COUNTIF work normally, and the column filter menu offers color filtering, although Microsoft notes some filter options may not be available in the browser. Per Microsoft’s list of browser differences, an .xlsm file opens but its macros don’t run, and workbooks that use Excel 4.0 macro functions such as GET.CELL can’t be displayed. Open the file in the desktop app for Methods 3 and 4.

Check the count and undo the setup

To double-check a number, compare two methods: the Find All total for one column should match the SUBTOTAL result for the same column and color. While filtered, the status bar also shows something like “14 of 199 records found.”

To clean up afterward:

  • Find: Format arrow > Clear Find Format.
  • Filter: press Ctrl + Shift + L again, or choose Clear Filter From in the column menu. The SUBTOTAL cell goes back to the full count.
  • VBA: in the editor, right-click Module1 > Remove Module1, then save as .xlsx. Formulas that used CountColor will show #NAME?, so delete them first.
  • GET.CELL: delete the helper column, then remove FillCode in Formulas > Name Manager.

Find All coming up empty or #NAME?

Find All says it can’t find anything

The cell you sampled probably has extra formatting (bold, a border, a number format) that the others don’t share. Clear the find format and set only the fill color under Format > Fill. Also check that Within is set to Sheet and that you didn’t select a range that excludes the colored cells.

CountColor shows #NAME?

Either macros are disabled for this file, or the code is in the wrong place. It must sit in a standard module (Insert > Module), not in a sheet’s or ThisWorkbook’s code window. Close and reopen the file and allow macros when prompted.

CountColor returns 0 for cells that are clearly colored

Those colors come from conditional formatting, or the sample cell is a slightly different shade. Use the conditional formatting options above, or point the formula at one of the actual highlighted cells.

The SUBTOTAL number doesn’t change after filtering

The formula’s range doesn’t cover the filtered rows, or the formula sits inside the filtered area and got hidden. Put it above the header row or below the data.