How to Sum by Color in Excel: A Step-by-Step Guide for Beginners

Summing by color in Excel is a nifty trick that can help you quickly add up values based on cell colors. To do this, you’ll need to use a combination of functions, like SUMIF, and a little bit of Visual Basic for Applications (VBA). Follow the steps below to make it happen.

How to Sum by Color in Excel

In this guide, we’ll walk you through how to sum values in Excel based on cell color. This involves a bit of VBA scripting to identify cell colors and then using those colors to sum the values.

Step 1: Open Excel and Press Alt + F11

To get started, press Alt + F11 to open the VBA editor. This is where you’ll write a custom function that will let you sum by color.

Once you’ve done that, you should see a new window pop up. This is the VBA editor where you can add new code.

Step 2: Insert a New Module

Next, click on Insert in the menu and then select Module. This will create a new module where you can write your VBA code.

In this module, you will write a custom function that can identify the color of a cell and sum the values based on that color.

Step 3: Write the VBA Code

Copy and paste the following code into the new module:

Function SumByColor(CellColor As Range, SumRange As Range)
    Dim ColorIndex As Integer
    Dim TotalSum As Double
    ColorIndex = CellColor.Interior.ColorIndex
    For Each Cell In SumRange
        If Cell.Interior.ColorIndex = ColorIndex Then
            TotalSum = TotalSum + Cell.Value
        End If
    Next Cell
    SumByColor = TotalSum
End Function

This code defines a function called SumByColor that takes two arguments: the cell color to look for and the range of cells to sum.

Step 4: Close the VBA Editor

After you’ve added the code, close the VBA editor by clicking the X in the upper-right corner.

You can now use your new function in Excel like any other function. Just type =SumByColor and provide the necessary arguments.

Step 5: Use the New Function

Go back to your Excel spreadsheet. Use the new function =SumByColor(A1, B1:B10) where A1 is the cell with the color you want to match, and B1:B10 is the range you want to sum.

This function will sum all the values in the range B1:B10 that have the same background color as the cell A1.

After completing these steps, your Excel sheet will sum values based on cell color. This can be incredibly useful for color-coded data sets.

Tips for Summing by Color in Excel

  • Use Conditional Formatting: Apply colors using conditional formatting for consistent color coding.
  • Double-Check Colors: Make sure the colors you are summing match exactly, as different shades won’t be summed together.
  • Save Your Work: Always save your Excel file before running any VBA scripts.
  • Test Your Function: Run a few test sums to ensure your new function works as expected.
  • VBA Security: If you’re sharing your Excel file, inform users that it contains macros, as some security settings might block them.

Frequently Asked Questions

How do I access the VBA editor in Excel?

Press Alt + F11 to open the VBA editor.

Can I sum by multiple colors at once?

No, the SumByColor function works for one color at a time. You’d need to use multiple functions for different colors.

Will this work on Excel online?

No, VBA scripts do not run in Excel Online. This method is only for desktop versions.

Is it possible to sum by color using only Excel functions?

Unfortunately, Excel functions alone cannot sum by color. VBA is required.

What if my cells contain text?

The SumByColor function is designed to work with numeric values. Text will not be summed.


  1. Open Excel and Press Alt + F11
  2. Insert a New Module
  3. Write the VBA Code
  4. Close the VBA Editor
  5. Use the New Function


Summing by color in Excel can make your data manipulation a breeze, especially if you rely on color-coded information. By following the steps above, you can create a custom function that effortlessly sums values based on cell color. This can save you a ton of time and help you maintain accuracy in your data analysis.

If you found this guide useful, consider exploring other VBA functions that can automate and enhance your Excel experience. Whether you’re a student, a professional, or just someone who loves organizing data, mastering these techniques can give you a real edge.

So why not give it a try? Open up Excel, dive into the VBA editor, and start summing by color today. Happy Excel-ing!

Get Our Free Newsletter

How-to guides and tech deals

You may opt out at any time.
Read our Privacy Policy