How to Find the Sum If the Cell Color Is Green in Excel (4 Easy Methods)

The following dataset has Month and Sales columns. The Sales column has several cells colored Green. Using this dataset, we will find the sum of the cells colored green.

Sample Excel Dataset with Some Green Colored Cells


Method 1 – Applying the SUMIF Function Using a Helper Column with Color Names Written Manually

Steps:

  • Enter the following formula in cell C12:
=SUMIF(D5:D11,"Green",C5:C11)

 Using SUMIF Function for Excel if cell color is green then sum

Formula Breakdown:

  • SUMIF(D5:D11, “Green”, C5:C11) the SUMIF function finds the sum of a range of cells based on specified criteria.
  • D5:D11 → is the range.
  • Green → is the criteria.
  • C5:C11 → is the sum_range.

Output: $4600

  • Press ENTER.
  • The result is in cell C12.

Result after using SUMIF Function for Excel if cell color is green then sum

Read More: How to Use If Statement Based on Cell Color in Excel


Method 2 – Using the SUBTOTAL Function and Applying the Filter Command to Filter Out Green Cells

Steps:

  • Enter the following formula in cell C12:
=SUBTOTAL(9,C5:C11)

 Applying the SUBTOTAL function to sum if cell color is green

Formula Breakdown:

  • SUBTOTAL(9, C5:C11) → the SUBTOTAL function finds out the subtotal in a range of cells.
  • 9 indicates the function_num.
  • C5:C11 is ref_1.

Output: $4600

  • Press ENTER.
  • The result is in cell C12.

The output of SUBTOTAL Function

  • To add the Filter icon to the column headings, we will select the column headings by selecting cells B4:C4.
  • Go to the Data tab >> select Filter.

Use of Filter feature

  • The Filter icon is in the column headings.

Added Filter con to Column Headings

  • Click on the Filter icon of the Sales >> select Filter by Color.
  • Click on the color green.

Here, you can insert a Table and use the Filter by Color to filter the Green color and find the sum of these green-colored cells.

Use of Filter by Color Command for Excel if cell color is green then sum

  • The Sum of the Green Colored Sales is in cell D12.

The result after using the Filter feature

Read More: How to Use Conditional Formatting If Statement Is Another Cell


Method 3 – Using the GET.CELL Function to Get a Color Code for Green and Sum Using the SUMIF Function

Steps:

  • Go to the Formulas tab >> select Name Manager.

Selecting Name Manager for Excel if cell color is green then sum

  • A Name Manager dialog box will appear.
  • Click on New.

Selecting New in the Name Manager dialog Box

  • A Name dialog box will appear.
  • In the Name box, enter color_code.
  • In the Refers to box, enter the following formula:

=GET.CELL(38, Sheet2!$C5)

Typing Formula in the New Name dialog box

  • Click Close.

Selecting Close in the Name Manager dialog box

  • Enter the following formula in cell D5:
=color_code

 Use of color_code function

  • Press ENTER.
  • The result is in cell D5.
  • Drag down the formula with the Fill Handle tool.

Applying the Fill Handle tool

  • The complete Color Code is in the column.

Complete Color Code

  • Enter the following formula in cell D12:
=SUMIF(D5:D11,4,C5:C11)
  • Press ENTER.
  • The result is in cell D12.

Result after using SUMIF Function for Excel if cell color is green then sum

Read More: SUMIF vs SUMIFS in Excel 


Method 4 – Using VBA Codes to Sum Green Cells Only

4.1. Get the Color Code with VBA and Then Apply the SUMIF Function to Get the Sum

Steps:

  • Go to the Developer tab >> select Visual Basic.
  • This will open a VBA Editor window. Press ALT+F11 to open the VBA Editor window.

Using Developer tab for Excel if cell color is green then sum

  • A VBA Editor window will open.
  • From the Insert tab >> select Module.

Inserting Module

  • Enter the following code in the Module:
Function index_for_color(CellColor As Range)
   index_for_color = CellColor.Interior.ColorIndex
End Function

VBA Code in the Module

  • Save the code >> go back to the Worksheet.
  • Enter the following formula in cell D5:
=index_for_color(C5)

Typing VBA function in cell D5.

  • Press ENTER.
  • The index of the color Green is in cell D5.
  • Drag down the formula with the Fill Handle tool.

Dragging Formula Using Fill Handle Tool

  • The complete Index for Color is in the column.

Complete Index for Color column

  • To find the Sum of the Green Colored Sales, enter the following formula in cell D12:

=SUMIF(D5:D11,4, C5:C11)

Applying SUMIF Function

  • Press ENTER.
  • The result is in cell D12.

Result after using SUMIF Function

Read More: How to Use 3D SUMIF for Multiple Worksheets in Excel


4.2. Create a VBA Function to Get Added Value for a Selected Color (Green)

Steps:

  • Follow the steps in 4.1 to open the Module.
  • Enter the following code in the Module:
Function Sum_by_Green_Color(Cell_Color As Range, rRange As Range)
Dim c_sum As Double
Dim col_index As Integer
col_index = Cell_Color.Interior.ColorIndex
For Each cl In rRange
   If cl.Interior.ColorIndex = col_index Then
   c_sum = WorksheetFunction.Sum(cl, c_sum)
   End If
Next cl
Sum_by_Green_Color = c_sum
End Function

VBA Code to Get Summed up Value

  • Go back to our Worksheet.
  • Enter the following formula in cell C13:
=Sum_by_Green_Color(C5,C5:C11)

Applying Sum_by_Green_Color Function

  • Press ENTER.
  • The result is in cell C13.

Result after using VBA for Excel if cell color is green then sum

Read More: How to Sum Colored Cells in Excel 


Practice Section

You can download the Excel file and practice the explained methods.

Practice Section for Excel if cell color is green then sum


Download the Practice Workbook

You can download the workbook to practice.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Afia Kona
Afia Kona

Afia Aziz Kona, a graduate of NAME from Bangladesh University of Engineering & Technology, Bangladesh, serves as a technical content creator in the ExcelDemy project. Possessing a passion for innovation and critical thinking, she actively embraces challenges. Beyond her engineering background, Afia exhibits a keen interest in Excel, having authored numerous articles on Excel & VBA-related issues to simplify the experience for users facing obstacles in Excel. Apart from creating Excel tutorials, she is also interested... Read Full Bio

2 Comments
  1. Thanks for the tutorial, now how do I sum the cells if the cell color is green, blue, and red?

    • Hello ZHENG,
      Thank you for taking the time to read our article. If you have cells of different colors (such as green, blue, and red) and want to sum them up, the easiest way is to use the SUBTOTAL function with the Filter command. For example, let’s say you have sales values in the range C5:C11, where cells C5, C7, and C10 are green, C6 and C8 are blue, and C9 and C11 are red. Illustrating Colored Cells
      1. To get the sum of a definite colored cell, insert the formula in a cell:=SUBTOTAL(9,C5:C11)
      Here, the SUBTOTAL function inserted in cell C12 uses 9 as the “function_name” argument (which refers to the SUM function) and C5:C11 as “ref1”. Inserting SUBTOTAL Formula
      2. Select the column header and go to the Data tab > Sort & Filter > Filter. Selecting Filter Command
      3. Click on the Filter icon of the column and select “Filter by Color.” You will see three different colors to choose from.
      4. Select the color you want to sum up, and you will get the sum of all the cells with that color. Choosing a color to filter by color
      You can see the blue-colored cells filtered and summed up.
      Cells Summed and Filtered by Color

      We hope this helps! Let us know if you have any further questions.

      Regards,
      Exceldemy Team

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo