This can be achieved using either of the two methods mentioned below –
Table of Contents
Download the Excel Workbook below to follow along and understand How to check IF cell color is green in Excel –
download excel workbookIF-Cell-Color-is-Green.xlsm
Let’s dive into these two elaborate examples.
Method 1 – GET.CELL Function
The GET.CELL function is a built-in function in Excel that retrieves information about the formatting, location, or contents of a cell. GET.CELL cannot be directly referred to in the worksheet. You can use the GET.CELL function within a named range or in conjunction with the Name Manager to retrieve specific information about a cell (like cell color).
Imagine a dataset with scores recorded in column A. The task at hand is to check if the cell color is green and display “Pass” if true, or “Fail” otherwise.
Follow the steps below to achieve this result –
STEP 1: Go to Formulas > Name Manager.
STEP 2: In the Name Manager dialog box, select New.
STEP 3: In the Name field, enter a name for your range. Here, use cellcolor.
STEP 4: In the Refers to field, enter your GET.CELL function.
=GET.CELL(38,Sheet1!A2)
STEP 5: Click Close to save the named range.
STEP 6: To check the cell color and display a message, type =cellcolor in cell B2.
STEP 7: Drag the formula down and inspect color values.
You can see that when the cell color is green, the value is 36 else it is 0. Let’s use the IF function to display a custom message if cell color is green.
STEP 8: Replace the existing function with the one mentioned below in cell B2.
=IF(cellcolor=36,”Pass”,”Fail”)
Upon execution, this formula will present “Pass” if the cell color is green and “Fail” otherwise.
This method provides a dynamic way to respond to cell colors within Excel, offering flexibility in processing and conveying information.
Method 2 – Macros in Excel
An alternative method is to use a VBA code and run it to get the desired result. Macros enable the automation of tasks, offering a comprehensive solution for advanced operations.
Follow the steps below to check if cell color is green using Macros –
STEP 1: Go to Developer > VBA Basic.
STEP 2: Select Insert > Module.
STEP 3: Copy and paste the following VBA function:
Function CheckCellColor(Range)<br /> If Range.Interior.Color = RGB(198, 224, 180) Then<br /> CheckCellColor = &amp;amp;amp;amp;amp;quot;Pass&amp;amp;amp;amp;amp;quot;<br /> Else<br /> CheckCellColor = &amp;amp;amp;amp;amp;quot;Fail&amp;amp;amp;amp;amp;quot;<br /> End If<br /> End Function
STEP 4: Save and close the VBA editor.
STEP 5: Go to cell B2 and type the following –
=CheckCellColor(A2)
STEP 6: Copy the formula down.
This formula will present “Pass” if the cell color is green and “Fail” otherwise.
Conclusion
Both methods offer distinct advantages; the GET.CELL function provides a formulaic approach, while Macros extend powerful automation capabilities. The choice depends on the complexity of your requirements.
Click here to learn more about Macros in Excel!
John Michaloudis is a former accountant and finance analyst at General Electric, a Microsoft MVP since 2020, an Amazon #1 bestselling author of 4 Microsoft Excel books and teacher of Microsoft Excel & Office over at his flagship MyExcelOnline Academy Online Course.