How to Fix Excel VBA UDF Returning #VALUE! with Range.DisplayFormat
Question details
Users need to resolve a #VALUE! error that occurs when a custom VBA function (UDF) calls Range.DisplayFormat from a worksheet cell.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user is attempting to evaluate or read the displayed formatting (like conditional formatting colors) of a cell by using a VBA user-defined function inside a worksheet cell.
- Observed behavior
- The cell returns a #VALUE! error because Excel restricts the use of the Range.DisplayFormat property within worksheet-called user-defined functions by design.
Ensure you have access to the Visual Basic for Applications (VBA) editor by pressing ALT + F11, as resolving this issue requires modifying your existing VBA code.
Replace the UDF with a Sub Procedure
Since Excel disables Range.DisplayFormat for functions called from cells, using a standard Macro (Sub procedure) bypasses this restriction.
A Sub procedure is not bound by the strict recalculation rules of worksheet cells. Therefore, it can freely access formatting properties and write the evaluated results directly back to the target cells.
Press ALT + F11 in Excel to open the Visual Basic for Applications window.
In your module, create a new Sub procedure (e.g., `Sub EvaluateFormat()`) instead of a Function.
Write your VBA code to read the formatting. For example: `Dim cellColor As Long; cellColor = Range("A1").DisplayFormat.Interior.Color`.
Add code to write the result directly to your desired cell: `Range("B1").Value = cellColor`.
Close the editor and run the macro from the Developer tab or assign it to a worksheet button to update your values.

Redesign Logic Using Underlying Values
Rewrite your user-defined function so that it evaluates the underlying data conditions rather than trying to read the physical format of the cell.
Try WPS Office for Seamless VBA Macro Management
If you are frustrated by specific execution restrictions in Microsoft Excel, WPS Office provides a lightweight, highly compatible, and robust alternative. WPS Spreadsheet comes equipped with advanced calculation capabilities and full macro support.
- 1. Download and Install: Visit the official WPS website, download the free version, and follow the simple installation instructions.
- 2. Open Your Spreadsheets: Launch WPS Spreadsheet and easily open your existing Excel workbooks and macro-enabled files.
- 3. Enable Macros: When prompted, simply enable macros to resume your VBA projects without losing compatibility.

Frequently Asked Questions
Why does Range.DisplayFormat work in a Macro but not a UDF?
Microsoft designed Excel to restrict user-defined functions called directly from worksheet cells. This is to prevent them from modifying the environment or getting caught in calculation loops. Because DisplayFormat relies on the user interface state, it is disabled during the strict worksheet recalculation phase.
Can a worksheet UDF modify the formatting of another cell?
No. A user-defined function called from a cell can only return a value to the cell or cells in which it is entered. It cannot alter the formatting, color, or values of other cells in the workbook.
Is there any direct workaround to force DisplayFormat inside a UDF?
There is no direct workaround to use the DisplayFormat property within a worksheet-called UDF. You must either use a Sub procedure (macro) to process the data or recreate the conditional formatting logic mathematically within your VBA code.




