If Cell Color Is Green Then Show or Customize Outputs in Excel

In the latest version of Excel, it is directly possible to use a specific cell color as the condition when using the IF function. But for previous versions, with a little help from Excel macros, there are some work-arounds allowing you to easily perform this task. In this tutorial, we are going to demonstrate what you can do with a cell value if the cell color is green or any other specific color in Microsoft Excel.

Defining a custom function with the help of the name defining feature will be a required step in all the operations we’ll perform below.


Example 1 – If Cell Color Is Green Then Set Cell Value

Let’s set cell values if the cell color is green in our sample dataset. From the dataset, we can see that our second and fifth entries are green. We want to associate “Absent” with them, and “Present” with the rest.

Let’s create the custom function to do this, then set the cell value if the cell color is green or any other color.

Steps to Define Custom Function:

  • Go to the Formulas tab on your ribbon.
  • Select Name Manager from the Defined Names.

excel if cell color is green then

  • The Name Manager box will open up. Now click on New on top of the box.

excel if cell color is green then

  • In the New Name box, enter a name for the function in the Name field.
  • In the Refers to field, enter the following:

=GET.CELL(38,Sheet1!B5)

excel if cell color is green then

  • Click on OK.

Now we have a formula called GreenCheck ready that can be used for other purposes.

Steps to Set Values:

  • To find out the color code of green (or any other color), select cell C5 and enter the following formula:

=GreenCheck

excel if cell color is green then

  • Press Enter and click and drag the Fill Handle to the end to find values for all.

We can see the color code of green is 50.

  • Clear the values you just entered.
  • Select cell C5 now and enter the following formula:

=IF(GreenCheck=50,"Absent","Present")

excel if cell color is green then

  • Press Enter.

  • Select the cell again. Click and drag the Fill Handle icon to the end of the list to replicate the formula for the rest of the cells.

excel if cell color is green then

 


Example 2 – If Cell Color Is Green Then Modify Cell Value

Let’s say there are values already associated with the cells, that we now want to modify.

Steps to Define Custom Function:

  • Go to the Formulas tab on your ribbon.
  • Select Name Manager.

excel if cell color is green then

  • The Name Manager box will open up. Click on New on top of the box.

excel if cell color is green then

  • In the New Name box, write down a name for the function in the Name field.
  • In the Refers to field, enter the following:

=GET.CELL(38,Sheet1!B5)

excel if cell color is green then

  • Click on OK.

Now we have the formula called GreenCheck ready that can be used for other purposes.

Steps to Modify Cell Values:

Let’s make a chart similar to the one in the previous Example.

  • Select cell C5 and enter the following formula:

=IF(GreenCheck=50,"Absent","Present")

excel if cell color is green then

  • Press Enter.

  • Select the cell again. Now click and drag the Fill Handle icon to the end of the list to replicate the formula for the rest of the cells.

excel if cell color is green then

Now let’s modify these values. Let’s say, we want the third entry to be green too.

  • Select cell B6.
  • Go to the Home tab of your ribbon.
  • Select Format Painter from the Clipboard group.

  • Click on cell B7.

excel if cell color is green then

The value of cell C7 will now automatically change to “Absent”.


Example 3 – If Cell Color Is Green Then Remove Cell Value

Now let’s say there are values already set on the dataset and we want to remove them based on their color. As before, first, we need the custom function.

Steps to Define Custom Function:

  • Go to the Formulas tab on your ribbon.
  • Select Name Manager from the Defined Names.

excel if cell color is green then

  • The Name Manager box will open up. Click on New on top of the box.

excel if cell color is green then

  • In the New Name box, enter a name for the function in the Name field.
  • In the Refers to field, enter the following:

=GET.CELL(38,Sheet1!B5)

excel if cell color is green then

  • Click on OK.

Now we have the formula called GreenCheck ready that can be used for other purposes.

Steps to Remove Cell Values:

Let’s say the dataset has the values shown below.

To remove the values associated with the green cells:

  • Select cell C5 and enter the formula:

=IF(GreenCheck=50,"","Present")

excel if cell color is green then

  • Press Enter.

You may not see any changes yet depending on your dataset.

  • Select cell C5 again and click and drag the Fill Handle icon to the end to replicate the formula.

excel if cell color is green then

The cell values will be cleared if the cell color of the adjacent cell is green.


Example 4 – If Cell Color Is Green Then Count Cells

Suppose the dataset looks like this:

excel if cell color is green then

To count the number of cells filled with green or any color we’ll utilize the COUNTIF function. But first, we need to define the custom function.

Steps to Define Custom Function:

  • Go to the Formulas tab on your ribbon.
  • Select Name Manager from the Defined Names.

excel if cell color is green then

  • The Name Manager box will open up. Click on New on top of the box.

excel if cell color is green then

  • In the New Name box, enter a name for the function in the Name field.
  • In the Refers to field, enter the following:

=GET.CELL(38,Sheet1!B5)

excel if cell color is green then

  • Click on OK.

Now we have the formula called GreenCheck ready that can be used for other purposes.

Steps to Count Cells:

  • To count the green cells, select cell C5 and enter the following formula:

=GreenCheck

excel if cell color is green then

  • Press Enter.

  • Select the cell again. Then click and drag the Fill Handle icon to the end of the column to fill the cells with the formula.

Now we have all the color codes of the adjacent cells in the dataset.

  • Select cell C12 and enter the following to count the green cells:

=COUNTIF(C5:C10,50)

excel if cell color is green then

  • Press Enter.

excel if cell color is green then

 


Example 5 – If Cell Color Is Green Then Sum Cell Values

Now let’s assume there are other values associated with the rows of the color-coded cells. For example, let’s look at the following dataset.

The way our color code functions are set up, the color code column has to be on the right of the colored cells.

Let’s use the SUMIF function to sum the values associated with green cells.

Steps to Define Custom Function:

  • Go to the Formulas tab on your ribbon.
  • Select Name Manager from the Defined Names.

excel if cell color is green then

  • The Name Manager box will open up. Click on New on top of the box.

excel if cell color is green then

  • In the New Name box, enter a name for the function in the Name field.
  • In the Refers to field, enter the following:

=GET.CELL(38,Sheet1!B5)

excel if cell color is green then

  • Click on OK.

Now we have the formula called GreenCheck ready that can be used for other purposes.

Steps to Sum Cell Values:

  • Select cell C5 and enter the following formula:

=GreenCheck

  • Press Enter.

  • Select the cell again and click and drag the Fill Handle icon to the end of the list to replicate the formula.

excel if cell color is green then

  • Select cell C12 and enter the formula:

=SUMIF(C5:C10,50,D5:D10)

excel if cell color is green then

  • Press Enter.

excel if cell color is green then

 


Download Practice Workbook


Related Articles


<< Go Back to Excel Get Cell ColorExcel Cell FormatLearn Excel

Get FREE Advanced Excel Exercises with Solutions!
Abrar-ur-Rahman Niloy
Abrar-ur-Rahman Niloy

Abrar-ur-Rahman Niloy, holding a B.Sc. in Naval Architecture and Marine Engineering, has contributed to Exceldemy for nearly 1.5 years. As a leader in Excel, VBA, and Content Development teams, he authored 114+ articles and assisted the Exceldemy forum. Presently, as a project writer, he prioritizes stepping out of his comfort zone, aiming for constant technical improvement. Niloy's interests encompass Excel & VBA, Pivot Table, Power Query, Python, Data Analysis, and Machine Learning libraries, showcasing his commitment to diverse... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo