If you want to find out the sum If the cell color is green in Excel, then you have come to the right place. Here, we will walk you through 4 easy methods to do the task smoothly.
Here, you can see in the following picture that we have found out the Sum of the Green Colored Sales in cell D12. In the following article. we will describe how you can also do the task.
Download Practice Workbook
You can download the Excel file from the following link and practice while reading this article.
4 Easy Methods to Find Sum in Excel If Cell Color Is Green
In the following dataset, you can see the Month and Sales columns. Here, you can easily notice that the Sales column has several cells colored in Green. Next, using this dataset we will find the sum if the cell color is green. Here, we used Excel 365. You can use any available Excel version.
1. Apply SUMIF Function Using a Helper Column with Color Names Written Manually
In this method, we will use the SUMIF function to find out the sum if the cell color is green. Here, we have added a Color column to our dataset. Next, we will use the SUMIF function to find out the sum of the Green color Sales.
Steps:
- First of all, we will type the following formula in cell C12.
=SUMIF(D5:D11,"Green",C5:C11)
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
- After that, press ENTER.
- Therefore, you can see the result in cell C12.
Read More: How to Use If Statement Based on Cell Color in Excel (3 Examples)
2. Use SUBTOTAL Function and Then Apply Filter Command to Filter Out Green Cells
In this method, we will use the SUBTOTAL function to find out the total Sales sum. Then, we will use the Filter feature to find the sum if the cell color is green.
Steps:
- In the first place, we will type the following formula in cell C12.
=SUBTOTAL(9,C5:C11)
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
- After that, press ENTER.
- Therefore, you can see the result in cell C12.
- Afterward, to add the Filter icon to the column headings, we will select the column headings bu selecting cells B4:C4.
- After that, go to the Data tab >> select Filter.
- As a result, you can see the Filter icon in the column headings.
- Moreover, we will click on the Filter icon of the Sales >> select Filter by Color.
- After that, click on the green color.
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.
- As a result, you can see the Sum of the Green Colored Sales in cell D12.
Read More: How to Use Conditional Formatting If Statement Is Another Cell
3. Use GET.CELL Function to Get Color Code for Green and Then Sum Using SUMIF Function
In this method, we will use the GET.CELL function from Name Manager to find the sum if the cell color is green.
Steps:
- First of all, we will go to the Formulas tab >> select Name Manager.
- After that, a Name Manager dialog box will appear.
- Then, click on New.
- After that, a New Name dialog box will appear.
- Then, in the Name box, we will type color_code.
- In addition, in the Refers to box, we will type the following formula.
=GET.CELL(38, Sheet2!$C5)
- Afterward, click on Close.
- Furthermore, we will type the following formula in cell D5.
=color_code
- In addition press ENTER.
- As a result, you can see the result in cell D5.
- Furthermore, we will drag down the formula with the Fill Handle tool.
- Hence, you can see the complete Color Code column.
- Next, we will type the following formula in cell D12.
=SUMIF(D5:D11,4,C5:C11)
- Afterward, press ENTER.
- Therefore, you can see the result in cell D12.
Read More: SUMIF vs SUMIFS in Excel (A Comparative Analysis)
Similar Readings
- How to Use IF Statement with Yes or No in Excel (3 Examples)
- How to Create a Formula in Excel to Calculate Percentage
- Excel IF Statement with VLOOKUP for Multiple Conditions Range
- Dynamic Data Validation List in Excel with IF Statement Condition
- How to Use IF Statement with Not Equal To Operator in Excel
4. Apply VBA Codes to Sum Green Cells Only
In this method, we will use VBA code to find the sum if the cell color is green in Excel. We will go through two ways to do tasks.
4.1. Get Color Code with VBA and Then Apply SUMIF Function to Get the Sum
Here, we will use the VBA function to find the sum if the cell color is green.
Steps:
- In the first place, go to the Developer tab >> select Visual Basic.
- This will bring out a VBA Editor window.
- Here, you can also press ALT+F11 to bring out the VBA Editor window.
- At this point, a VBA Editor window will appear.
- Then, from the Insert tab >> select Module.
- Furthermore, we will type the following code in the Module.
Function index_for_color(CellColor As Range)
index_for_color = CellColor.Interior.ColorIndex
End Function
- Next, Save the code >> go back to the Worksheet.
- Then, we will type the following formula in cell D5.
=index_for_color(C5)
- Furthermore, press ENTER.
- After that, you can see the index of the color Green in cell D5.
- Moreover, we will drag down the formula with the Fill Handle tool.
- Hence, you can see the complete Index for Color column.
- Afterward, to find the Sum of the Green Colored Sales, we will type the following formula in cell D12.
=SUMIF(D5:D11,4, C5:C11)
- In addition, press ENTER.
- Hence, you can see the result in cell D12.
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)
Here, we will use the VBA code to get the summed-up value if the cell color is green in Excel.
Steps:
- First, we followed the steps of 5.1 to bring the Module.
- After that, we type 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
- After that, we will go back to our Worksheet.
- Next, we will type the following formula in cell C13.
=Sum_by_Green_Color(C5,C5:C11)
- After that, press ENTER.
- Therefore, you can see the result in cell C13.
Read More: How to Sum Colored Cells in Excel (4 Ways)
Practice Section
You can download the Excel file and practice the explained methods.
Conclusion
Here, we show you 4 easy methods for Excel if the cell color is green then sum. Thank you for reading this article. We hope it was helpful. If you have any queries, please let us know in the comment section. You can visit our website ExcelDemy for more related articles.
Related Articles
- Use If Then Else Statement in Excel VBA (4 Examples)
- How to Ignore Blank Cells in Excel Sum (6 Ways)
- Excel IF Statement Between Two Numbers (4 Ideal Examples)
- How to Prepare IF Statement Contains Multiple Words in Excel
- Use Wildcard with If Statement in Excel (5 Methods)
- How to Use IF Function with OR and AND Statement in Excel
- Use Multiple IF Statements in Excel Data Validation