How to Calculate Percentage in Excel Based on Cell Color (4 Methods)

To illustrate our methods for calculating percentage based on cell color, we’ll use the following sample dataset representing the Salesman, Product, and Net Sales of a company. We have colored the net sales of some salesman. Let’s calculate the percentage of the total net sales that the colored net sales comprise.

calculate percentage in excel based on cell color


What is Percentage?

A number or ratio expressed as a fraction of 100 is known as a Percentage. The sign for percentage is ‘%’. The basic percentage is calculated by the formula:

Percentage = (Part / Whole)*100


Calculating Percentage Based on Cell Color


Method 1 – Using the SUBTOTAL Function

We’ll use the Excel SUBTOTAL function along with the Filter feature here.

STEPS:

  • Select cell D12 and enter the formula:
=SUBTOTAL(9,D5:D10)

Excel SUBTOTAL Function to Calculate Percentage Based on Cell Color

Here, 9 is the function number for SUM and D5:D10 is the range of cells.

  • Press Enter to return the sum result.
  • Copy the result and paste it as a value in cell F4.

Excel SUBTOTAL Function to Calculate Percentage Based on Cell Color

  • Select the range of cells you want to work with.

Excel SUBTOTAL Function to Calculate Percentage Based on Cell Color

  • Select Filter from the Sort & Filter drop-down in the Editing group under the Home tab.

Excel SUBTOTAL Function to Calculate Percentage Based on Cell Color

  • Select the drop-down icon beside Net Sales.
  • Select the Green colored box in the Filter by Cell Color options.

Excel SUBTOTAL Function to Calculate Percentage Based on Cell Color

You’ll see the Green colored cells only.

Additionally, the sum result in cell D12 will get updated automatically, and now it’ll return the sum of those green-colored cells only.

Excel SUBTOTAL Function to Calculate Percentage Based on Cell Color

  • Select cell D13 and enter the formula:
=D12/F4

Excel SUBTOTAL Function to Calculate Percentage Based on Cell Color

  • Press Enter.

  • Select the ‘%’ icon in the Number group under the Home tab.

The desired percentage value of green-colored cells will be returned.

Related Content: How to Calculate Percentage Complete Based on Dates in Excel


Method 2 – Using the SUMIF Function

The SUMIF function computes the sum of a range of cells based on a specific condition given in the argument.

STEPS:

  • Select Define Name from the Define Names drop-down under the Formulas tab.

Apply SUMIF Function for Calculating Percentage Based on Cell Color

A dialog box will pop out.

  • There, enter ColoredNumber in the Name section.
  • In the Refers to section, enter the formula:
=GET.CELL(38,‘sumif’!$D5)
  • Click OK.

Apply SUMIF Function for Calculating Percentage Based on Cell Color

Here, the GET.CELL function takes 38 to return the code color, sumif is the name of the worksheet and D5 is the cell reference.

A Name Manager dialog box will pop out

  • Click Close.

Apply SUMIF Function for Calculating Percentage Based on Cell Color

  • Select cell E5 and enter:
=ColoredNumber

Apply SUMIF Function for Calculating Percentage Based on Cell Color

  • Press Enter and use the AutoFill tool to fill the series.

The color codes will be returned.

Apply SUMIF Function for Calculating Percentage Based on Cell Color

  • Select cell D12 and enter the formula:
=SUM(D5:D10)

Apply SUMIF Function for Calculating Percentage Based on Cell Color

  • Press Enter.
  • Select cell D13 and enter the formula:
=SUMIF(E5:E10,E8,D5:D10)

Here, E5:E10 is the criteria range, E8 is our criteria and D5:D10 is the sum range.

  • Press Enter.
  • Select cell D14 and type the formula:
=D13/D12

  • Press Enter and select the ‘%’ icon in the Number group under the Home tab.

The accurate percentage result will appear in cell D14.

Related Content: How to Calculate Percentage Based on Conditional Formatting


Method 3 – Using the Excel SUMIFS Function

STEPS:

  • Select Define Name from the Define Names drop-down under the Formulas tab.

Cell Color Based Percentage Calculation with Excel SUMIFS Function

A dialog box will pop out.

  • In the Name section, enter ColorCode.
  • In the Refers to section, enter the formula:
=GET.CELL(38,sumifs!$D5)
  • Press OK.

Cell Color Based Percentage Calculation with Excel SUMIFS Function

Here, the GET.CELL function takes 38 to return the code color, the name of the worksheet is sumifs and Cell D5 is the cell reference.

A Name Manager dialog box will pop out.

  • Click Close.

Cell Color Based Percentage Calculation with Excel SUMIFS Function

  • Select cell E5 and enter:
=ColorCode

Cell Color Based Percentage Calculation with Excel SUMIFS Function

  • Press Enter and use the AutoFill tool to fill the series.

Cell Color Based Percentage Calculation with Excel SUMIFS Function

  • Select cell D12 and enter the formula:
=SUM(D5:D10)

Cell Color Based Percentage Calculation with Excel SUMIFS Function

  • Press Enter.
  • Select cell D13 and enter the formula:
=SUMIFS(D5:D10,E5:E10,E6)

Here, D5:D10 is the sum range, E5:E10 is the criteria range and E6 is the criteria.

  • Press Enter.
  • Select cell D14 and type the formula:
=D13/D12

  • Press Enter and select the ‘%’ icon in the Number group under the Home tab.

The precise percentage value will appear in cell D14:


Method 4 – Using Excel VBA

STEPS:

  • Select Visual Basic under the Developer tab.

Percentage Calculation Based on Cell Color with Excel VBA

A new window will pop out.

  • Select Module under the Insert tab.

Percentage Calculation Based on Cell Color with Excel VBA

As a result, another window will pop out.

  • There, paste the code given below:
Function ColorTotal(CClr As Range, rRng As Range)
Dim sum As Long
Dim color As Integer
color = CClr.Interior.ColorIndex
For Each cl In rRng
If cl.Interior.ColorIndex = color Then
sum = WorksheetFunction.sum(cl, sum)
End If
Next cl
ColorTotal = sum
End Function

Percentage Calculation Based on Cell Color with Excel VBA

  • Close the Visual Basic window.
  • Select cell D12 and enter the formula:
=SUM(D5:D11)

Percentage Calculation Based on Cell Color with Excel VBA

  • Press Enter.
  • Select cell D13 and enter the formula:
=ColorTotal(D5,D5:D10)

Percentage Calculation Based on Cell Color with Excel VBA

  • Press Enter.
  • Select cell D14 and enter the formula:
=D13/D12

  • Press Enter .
  • Select the ‘%’ icon in the Number group under the Home tab.

The percentage of the colored cells to the total net sales will appear in cell D14.

Read More: Calculate Percentage in Excel VBA


Download Practice Workbook


Related Articles


<<Go Back to Calculate Percentage with Criteria in Excel | Calculating Percentages in Excel | How to Calculate in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Aung Shine
Aung Shine

Aung Shine completed his bachelor’s in Electrical and Electronics Engineering from Bangladesh University of Engineering and Technology. It has been almost 2 years since he joined SOFTEKO and actively working on the ExcelDemy project. Currently he works as a Team Leader where he guides his team members to create technical content. He has published 150+ articles and reviewed 50+ articles. He has also solved various user problems before. He has interests in Data Analysis, Power Query, Advanced Excel,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo