Summing Cells Using a Particular Background Color

Written by Allen Wyatt (last updated April 9, 2026)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021


6

Peter has columns of dollar amounts that customers owe. When a customer pays, he highlights that cell in yellow by filling the cell with a yellow background color. Peter wonders if there is a way to sum only the cells that are highlighted in a particular column.

There are a few ways you can approach this problem, each of which I'll address in the following sections.

Filter and Use SUBTOTAL

A simple two-pronged approach is to filter your data based on the color you want to sum. Then, once filtered, you can rely on the results returned by the SUBTOTAL function.

In order to filter your data according to color, follow these steps:

  1. Make sure your data has column headings defined.
  2. Select a cell within your data.
  3. Display the Data tab of the ribbon.
  4. Click the Filter tool in the Sort & Filter group. Excel places a drop-down arrow next to the column headings.
  5. Click the drop-down arrow next to the heading of the column containing the colored cells. You'll see a number of filtering options displayed.
  6. Click the By Color drop-down list. Different color options appear, depending on the characteristics of your cell formatting.
  7. Hover the mouse pointer over the Cell Color option and then click on the color you want to use in your filtering. In Peter's case, this would be Yellow. Excel immediately filters the data by the selected color.
  8. Make sure that only the FALSE value has a check mark next to it.
  9. Click in a cell in the data table. This dismisses the filtering options first visible in step 5.

At this point you can enter a formula (in any cell you want) that will return the desired sum. Assuming that you want a sum of the values in C2:C93, you would use the following:

=SUBTOTAL(9,C2:C93)

This works because the SUBTOTAL function sums only values that remain visible after filtering. In this case, it means that only the yellow cells are summed.

Revamp Your Data

There is a very strong argument to be made for taking a look at how your data is organized in the worksheet. Applying a static color to cells isn't a terribly robust method of marking a row as "paid." A better way would be to add a column next to the amount column and use that new column to indicate if the amount has been paid. Then, if desired, you could use Conditional Formatting to highlight the values using any color you want, based on what you entered in the new column.

How does help when you need a sum of the colored cells? Simple—you aren't basing the sum on the color (applied via Conditional Formatting), but on the value in the column next to the amount. For instance, let's say that your amounts are in column A, so in column B you enter the letter "Y" if the adjacent amount has been paid. Now all you need to do is to use the following formula to determine the total of all the lines marked as paid:

=SUMIF(B:B,"Y",A:A)

The advantage to reorganizing your data in this manner is that your information about what has been paid—and what hasn't—is immediately "accessible" to other formulas and can even be exported to other programs. (You cannot export the color of a cell to another program.)

Use a Macro

The final approach to getting the sum you want is to use a macro. It is best to implement a user-defined function that can be accessed from your worksheet. This one will look at a specified range of cells and return the sum of any cell that is filled with yellow:

Function SumYellow(rTarget As Range)
    Dim c As Range
    Dim dTotal As Double

    Application.Volatile
    dTotal = 0
    For Each c In rTarget
        If c.Interior.Color = vbYellow Then
            dTotal = dTotal + c.Value
        End If
    Next c
    SumYellow = dTotal
End Function

In order to use the UDF in your worksheet, you would enter something similar to the following, assuming that the range containing the values is A2:A93:

=SumYellow(A2:A93)

If you think it is possible that a cell in the specified range might contain a text value instead of a numeric, then you should modify the macro just a bit:

Function SumYellow(rTarget As Range)
    Dim c As Range
    Dim dTotal As Double

    Application.Volatile
    dTotal = 0
    For Each c In rTarget
        If c.Interior.Color = vbYellow Then
            If IsNumeric(c) Then dTotal = dTotal + c.Value
        End If
    Next c
    SumYellow = dTotal
End Function

This version checks whether the cell contains a value or not before adding it to the dTotal variable. If the cell contains a non-numeric value, then it is skipped entirely.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13346) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Searching for Paragraph Formatting

You can use the Find and Replace capabilities of Word to search for a wide variety of information. One thing you can look ...

Discover More

Automatic Row Height for Wrapped Text

When you format a cell so that the information within it can wrap to multiple lines, you may be surprised if Excel ...

Discover More

Converting from Relative to Absolute

Addresses used in a formula can be either relative or absolute. If you need to switch between the two types of ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Compiling a List of Students in a Course

Need to pull just a limited amount of information from a large list? Here are a few approaches you might be able to use ...

Discover More

Calculating Unique IDs Based on Names and Initials

Sometimes it can be tricky to figure out how to get exactly what you want from a dataset. In this tip, you discover how ...

Discover More

Extracting Foreign-Language Characters

If you need to analyze some text to determine if it contains accented characters, there are a couple of ways you can ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is eight minus 5?

2026-04-15 16:36:28

J. Woolley

My Excel Toolbox includes the following function to return the displayed fill color RGB value for each cell in a range:
=FillColor([Target])
If Target is omitted, the formula's cell applies. If Target is multicell, its first contiguous area applies. Conditional formatting is accommodated.
Either of the following formulas will sum numeric cells in C2:C93 that have the same fill color as cell D2:
=SUMPRODUCT(C2:C93, --(FillColor(C2:C93)=FillColor(D2)))
=SUMIF2(FillColor(C2:C93), FillColor(D2), C2:C93)
The 2nd formula uses My Excel Toolbox's SUMIF2 because Excel's SUMIF will not work with an array as its first argument.
See https://sites.google.com/view/MyExcelToolbox/


2026-04-12 10:25:36

Kiwerry

@ J. Woolley:
Thank you, I'll try that out. Keep well.


2026-04-11 16:16:07

J. Woolley

Re. my previous comment below, Function SumSameColor will not work correctly in a cell formula if Target or Reference are not on the same worksheet as the formula's cell. To fix it, replace both references to a range's Address property with Address(External:=True).


2026-04-10 20:08:54

J. Woolley

@Kiwerry
Unfortunately the Range.DisplayFormat property is unavailable for direct access in a UDF, but it can be obtained indirectly using the Application.Evaluate method. Here's an alternate version of the Tip's UDF to sum numeric cells in Target that have the same fill color as the first cell in Reference:

Public Function SumSameColor(Target As Range, Reference As Range)
    Dim c As Range, dTotal As Double, vColor As Variant
    Application.Volatile
    vColor = Evaluate("Get_Fill_Color(" & Reference.Cells(1).Address & ")")
    For Each c In Target
        If Evaluate("Get_Fill_Color(" & c.Address & ")") = vColor Then
            If IsNumeric(c) Then dTotal = dTotal + c.Value
        End If
    Next c
    SumSameColor = dTotal
End Function

Private Function Get_Fill_Color(r As Range)
    Get_Fill_Color = r.DisplayFormat.Interior.Color
End Function

This version does not ignore conditional formatting.


2026-04-09 08:46:36

Kiwerry

Thanks as ever for a useful tip, Allen.
The comment below motivated me to try the function out. It worked for me, but only if the colour is a fixed fill; the same colour applied by conditional formatting is ignored. Apparently using
c.DisplayFormat.Interior.Color
instead of
c.Interior.Color
is the way to go, but I haven't tried it.

@Muhammad: Apart from the abovementioned, a question is, whether the cells you are testing have the colour vbYellow or simply look yellow but it's a different shade of yellow? If that's possible you need to check the RGB value of the colour used


2021-02-07 04:37:53

Muhammad Adnan Shakil

Dear Sir,

This function isn't working.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.