Range.DisplayFormat Property (Excel)
Returns a DisplayFormat object that represents the display settings for the specified range. Read-only
expression A variable that represents a 'Range' object.
Note that the DisplayFormat property does not work in user defined functions. For example, in a worksheet function that returns the interior color of a cell, you use a line similar to:
Range(n).DisplayFormat.Interior.ColorIndex. When the worksheet function executes, it returns a #VALUE! error.
In another example, you cannot use the DisplayFormat property in a worksheet function to return settings for a particular range. DisplayFormat will work in a function called from Visual Basic for Applications (VBA), however. For instance, in the following function:
Function getColorIndex() getColorIndex = ActiveCell.DisplayFormat.Interior.ColorIndex End Function
Calling the function from a worksheet as follows =getColorIndex() returns the #VALUE! error.
However, when the function is called from the Immediate pane in the Visual Basic Editor, it returns the color index for the active cell. To work around this issue, remove DisplayFormat from the code. The following function will work either from a worksheet or from VBA:
Function getColorIndex() getColorIndex = ActiveCell.Interior.ColorIndex End Function