Lookup Values Based on Cell Fill Color in Excel

📅 Feb 07, 2026 📝 Sarah Miller

Many Excel users struggle when trying to retrieve critical data based on cell fill color rather than raw cell values. While standard lookup functions like VLOOKUP or XLOOKUP excel at scanning text and numbers, they are blind to visual formatting. Unlocking this capability grants you a powerful way to leverage visual metadata, though standard Excel rules stipulate the use of VBA (Visual Basic for Applications) to extract background color codes. For example, identifying "green-lighted" budgets requires a custom User Defined Function. Below, we provide a step-by-step guide to implementing this advanced lookup solution.

Lookup Values Based on Cell Fill Color in Excel

Excel is an incredibly powerful tool for organizing and analyzing data, but it has a well-known limitation: its native formula library is built to read and manipulate values, not formatting. If you have ever inherited a spreadsheet where key information is communicated solely through cell fill colors-such as green for "approved," yellow for "pending," or red for "urgent"-you have likely faced the challenge of trying to perform a lookup based on those colors.

Standard Excel formulas like VLOOKUP, INDEX/MATCH, and XLOOKUP cannot natively detect the fill color of a cell. However, there are highly effective workarounds to solve this problem. In this comprehensive guide, we will explore three distinct methods to lookup and retrieve values based on cell fill colors: using a legacy Excel 4.0 named formula, creating a custom VBA User-Defined Function (UDF), and implementing best-practice design alternatives.


Method 1: The No-VBA Solution Using Excel 4.0 Named Formulas

If you cannot or do not want to use VBA macro code (perhaps due to company security policies), you can use an old but powerful legacy tool: Excel 4.0 Macro Functions. Specifically, we will use the GET.CELL function.

Because this is a legacy macro function, it cannot be typed directly into a worksheet cell. Instead, we must define it inside Excel's Name Manager.

Step-by-Step Instructions:

  1. Select cell B2 (or the cell directly adjacent to your colored cell in row 2). This relative positioning is crucial.
  2. Go to the Formulas tab on the Ribbon and click on Define Name.
  3. In the Name box, type a clear name like GetCellColor.
  4. In the Refers to box, enter the following formula:
    =GET.CELL(63, Sheet1!A2)
    Note: Code 63 tells Excel to return the fill color index of the referenced cell. Ensure the sheet name matches your active sheet, and the cell reference (A2) points to the colored cell in the same row.
  5. Click OK.

Using the Helper Column to Perform the Lookup:

Now that you have defined the name, you can create a helper column that extracts the color code from your target cells:

  1. In cell B2, enter the formula: =GetCellColor
  2. Drag this formula down your helper column. You will see numerical color codes appear (e.g., 3 for red, 4 for green, etc.).
  3. Now, you can use a standard VLOOKUP or XLOOKUP formula to search for a specific color code and return its corresponding value.
Column A (Colored Cell) Column B (Helper: =GetCellColor) Column C (Value to Retrieve)
Item 1 (Red Fill) 38 (Color Index) $120.00
Item 2 (Green Fill) 43 (Color Index) $340.00

Important Save Requirement: Because this workbook now contains a legacy macro function, you must save your file as an Excel Macro-Enabled Workbook (.xlsm) to retain this functionality.


Method 2: The VBA User-Defined Function (The Most Dynamic Approach)

If you want a clean, direct formula in your worksheet without using helper columns, creating a custom function with VBA (Visual Basic for Applications) is the best solution. We will write a function called LookupByColor that behaves just like VLOOKUP, but searches for a color match instead of a text match.

The VBA Code:

To insert the code, press ALT + F11 to open the VBA Editor. Click Insert > Module, and paste the following code into the empty module window:

Function LookupByColor(TargetColorCell As Range, LookupRange As Range, ReturnRange As Range) As Variant
    Dim cell As Range
    Dim targetColor As Long
    Dim i As Long
    
    ' Get the fill color of the reference cell
    targetColor = TargetColorCell.Interior.Color
    
    ' Loop through the lookup range to find a matching color
    For i = 1 To LookupRange.Cells.Count
        If LookupRange.Cells(i).Interior.Color = targetColor Then
            ' Return the corresponding value from the return range
            LookupByColor = ReturnRange.Cells(i).Value
            Exit Function
        End If
    Next i
    
    ' Return #N/A if no matching color is found
    LookupByColor = CVErr(xlErrNA)
End Function

How to Use the Custom Formula:

Once the code is in place, return to your Excel worksheet. You can now use your custom function just like any native Excel formula. The syntax is:

=LookupByColor(TargetColorCell, LookupRange, ReturnRange)

Example Scenario:

  • You have a list of colored cells in range A2:A10.
  • The values you want to retrieve are in range B2:B10.
  • You have a reference cell with the specific color you are searching for in cell D2.

In your target cell, write the following formula:

=LookupByColor(D2, A2:A10, B2:B10)

This formula checks the background color of cell D2, searches for that exact color in the range A2:A10, and returns the corresponding value from the same position in B2:B10.


Important Limitations of Color-Based Calculations

While these workarounds are highly effective, it is vital to understand the fundamental limitations of using formatting as a data driver in Microsoft Excel:

  • Formatting changes do not trigger recalculations: When you change the value of a cell, Excel automatically recalculates all formulas. However, changing a cell's fill color does not trigger a recalculation. If you update a cell's color, you must force recalculation manually by pressing F9 or saving the sheet.
  • Conditional Formatting Conflict: The standard VBA property Range.Interior.Color reads manually applied fill colors. It cannot easily detect colors applied dynamically through Conditional Formatting rules. If your colors are generated by conditional formatting, you should instead perform your lookup based on the logical rules that triggered the conditional formatting in the first place.
  • Collaboration Hurdles: Mac versions of Excel and Excel for the Web have limited support for macros and legacy functions, which may cause these workarounds to fail when shared with other users.

Best Practice Alternative: Reverse Your Workflow

In data architecture, formatting should always be a visual consequence of data, not the data itself. Instead of entering data as a color and trying to extract values from it, you should design your sheets so that data is entered as text or numbers first, and then use Conditional Formatting to apply the color visually.

For example, instead of coloring a cell yellow to indicate "Pending," create a "Status" column and type "Pending." From there:

  1. Use standard, reliable XLOOKUP formulas to lookup the text value "Pending."
  2. Apply a Conditional Formatting rule that automatically colors the row yellow whenever the status equals "Pending."

This approach gives you the exact same visual aesthetics while maintaining a robust, error-free, and natively formula-supported spreadsheet structure.


Summary

When you are stuck with inherited sheets that rely on color coding, you don't have to resort to manual copying and pasting. Use the Excel 4.0 Name Manager trick if you need a quick, no-code helper column solution, or implement the VBA User-Defined Function for a clean, direct formula approach. For future projects, strive to store your attributes as text data, utilizing conditional formatting to safely handle the visual presentation of your data.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.