Excel Formula: If Cell Color is Green Then Do Something


Often you may want to use an IF statement in Excel to perform some action if a cell color is green.

Fortunately this is easy to do by creating a Defined Name in Excel that can check whether or not a cell is green.

The following example shows how to do so in practice.

Example: If Cell Color is Green Then Do Something in Excel

Suppose we have the following list of basketball players in Excel in which the green cells indicate that the player is an All-Star:

Suppose we would like to use an IF statement to check if each cell color in column A is green and return either “All-Star” or “Not All-Star” in column B.

To do so, we can click the Formulas tab along the top ribbon, then click the Name Manager icon:

In the new window that appears, click the New button in the top left corner:

In the new window that appears, type GreenCell in the Name box, then type =GET.CELL(38,Sheet1!A2) in the Refers to box, then click OK:

Next, type =GreenCell in cell B2, then click and drag this formula down to each cell in column B:

We can see that the formula returns a color code of 35 for each corresponding cell in column A that is green.

Now that we know which color code represents this shade of green, we can type the following formula into cell B2 to return “All-Star” if the corresponding cell in column A is green or “Not All-Star” otherwise:

=IF(GreenCell=35, "All-Star", "Not All-Star")

We can then click and drag this formula down to each remaining cell in column B:

Excel if cell color is green then

Column B now returns “All-Star” or “Not All-Star” depending on whether or not the corresponding cell in column A is green.

Note that in this particular example, the shade of green that we used had a color code of 35.

However, different shades of green will have a different color code, which is why we created the GreenCell custom formula to actually extract the color code before we created the IF statement.

Additional Resources

The following tutorials explain how to perform other common operations in Excel:

Excel: How to Change Font Color Based on Cell Value
Excel: How to Alternate Column Colors
Excel: How to Count Cells by Color

2 Replies to “Excel Formula: If Cell Color is Green Then Do Something”

    1. Hi Jessica…In Excel, **formulas cannot directly detect cell colors**, including specific shades of a color. However, you can use **VBA (Visual Basic for Applications)** to create a function that can detect the color of a cell, including specific shades of green.

      Here’s how you can achieve this using VBA to check for a specific shade of green:

      ### 1. **Open the VBA Editor:**
      – Press `Alt + F11` to open the VBA editor in Excel.

      ### 2. **Insert a New Module:**
      – In the VBA editor, click `Insert` > `Module`.

      ### 3. **Create a VBA Function to Check Cell Color:**
      – Paste the following code into the module:

      “`vba
      Function GetCellColorCode(cell As Range) As Long
      GetCellColorCode = cell.Interior.Color
      End Function
      “`

      This function will return the **color code** (a number) for the background color of the specified cell.

      ### 4. **Using the Function in Excel:**
      – After adding this function, you can use it in your worksheet like any other formula. For example, to get the color code of a cell (say, A1), enter this formula in another cell:

      “`excel
      =GetCellColorCode(A1)
      “`

      – The function will return the color code of the background of cell A1.

      ### 5. **Checking for Specific Shades of Green:**
      Each shade of green will have a unique color code. For instance:
      – A light green might have a color code like `5296274`.
      – A darker shade might have a different code, such as `65280`.

      You can check for a specific shade using the **IF function** like this:

      “`excel
      =IF(GetCellColorCode(A1) = 5296274, “Light Green”, “Other Color”)
      “`

      ### 6. **Changing the Formula Based on Different Shades:**
      If you need to check for multiple shades of green, you can modify the formula to handle different color codes for different shades:

      “`excel
      =IF(GetCellColorCode(A1) = 5296274, “Light Green”, IF(GetCellColorCode(A1) = 65280, “Dark Green”, “Other Color”))
      “`

      ### Note:
      – You will need to first determine the exact color code for each shade of green by applying the function `=GetCellColorCode()` to the cells with the colors you are using.

      By using this VBA approach, you can work with specific shades of green and detect them within your Excel workbook.

Leave a Reply

Your email address will not be published. Required fields are marked *