Function Problems

How to Return Cell Color and Formatting with an Excel Lookup

Ayan MasoodAyan Masood Oct 23, 2026 869 views

Question details

The user wants to perform a lookup that returns not just the cell's data value, but also its formatting attributes such as fill color, font style, and borders.

How to Return Cell Color and Formatting with an Excel Lookup
Product
Microsoft Excel
Device & OS
not provided
Scenario
Attempting to retrieve source cell visual formatting alongside data values using functions like VLOOKUP or INDEX/MATCH.
Observed behavior
Standard Excel lookup formulas only extract data values, ignoring the original cell's background color, font, and other stylistic properties.
Before you start

Since standard Excel formulas cannot extract cell formatting, ensure you have the Developer tab enabled to use VBA macros, and note that retrieving conditional formatting requires more complex programmatic handling.

Solution 1Recommended

Use a VBA User-Defined Function (UDF) to Copy Formatting

Since standard lookup formulas cannot return cell colors or fonts, you must use a custom VBA script to pull the static formatting from a reference cell.

Excel's built-in lookup functions are designed exclusively for retrieving data. To extract cell properties like background color or font size, you must write a VBA macro or User-Defined Function (UDF). Note that standard UDFs struggle to accurately return conditional formatting results and work best for static formats.

1
Enable the Developer Tab

Go to File > Options > Customize Ribbon, and check the 'Developer' box in the right-hand list to enable macro tools.

2
Open the VBA Editor

Click 'Visual Basic' on the Developer tab or press Alt + F11 on your keyboard.

3
Create a New Module

Right-click on your workbook name in the VBA Project pane, select 'Insert', and click 'Module'.

4
Enter the Custom VBA Code

Write or paste a VBA script designed to read the source cell's .Interior.Color or .Font properties and apply them to the target cell based on your lookup criteria.

5
Apply Your Custom Function

Return to your worksheet and type your new custom function just like a standard Excel formula, referencing the range that contains the desired color or format.

Use a VBA User-Defined Function (UDF) to Copy Formatting
Conditional Formatting Limitation: Standard UDFs usually retrieve the base formatting of a cell, not the dynamic formatting applied by Conditional Formatting rules. Advanced macros using the DisplayFormat property are required for conditionally formatted cells.

Manage Data Lookups and Macros Effortlessly in WPS Spreadsheet

WPS Office provides a highly compatible and powerful spreadsheet tool that seamlessly handles complex lookup functions, conditional formatting, and VBA macros to help you style and manage your data exactly like Microsoft Excel.

  1. 1. Open Your Workbook in WPS Spreadsheet: Launch WPS Office and open the document containing your lookup data or macro-enabled file.
  2. 2. Apply Conditional Formatting: Navigate to the Home tab and use the Conditional Formatting feature to apply dynamic colors based on your lookup values without needing complex VBA.
  3. 3. Run Custom Macros: If you require exact format copying, enable macros within WPS Spreadsheet to run the same VBA custom functions used in Excel.
Full compatibility with Microsoft Excel formats, including .xlsx and macro-enabled .xlsm files.Built-in support for advanced macros and User-Defined Functions.Intuitive Conditional Formatting tools to dynamically style lookup results.Free and lightweight software that processes complex data lookups quickly.
microsoft office alternative - wps office

Frequently Asked Questions

Can standard lookup functions like VLOOKUP or XLOOKUP return a cell's background color?

No, standard lookup functions only retrieve the raw data value stored in a cell. They are not programmed to extract metadata such as background color, font color, or borders.

Why does my VBA function ignore conditional formatting?

Standard VBA properties read the cell's underlying static format. Conditional formatting applies layered formats dynamically. To read these, you must evaluate the DisplayFormat property, which standard User-Defined Functions cannot reliably return during routine worksheet recalculations.

How can I match cell colors without using VBA macros?

If you cannot or prefer not to use VBA, the best alternative is applying identical Conditional Formatting rules to both your source data and your lookup destination cells, ensuring they automatically format the same way based on the data values.