Getting cell Interior Color Fails when range passed from Worksheet function

后端 未结 2 1448
离开以前
离开以前 2021-01-16 06:51

I am trying to get write a simple function one can call from a cell that would return if the background of a given cell has a specific background color.

This functio

2条回答
  •  旧时难觅i
    2021-01-16 07:29

    Here's a workaround to the "DisplayFormat not available in a UDF" problem.

    It uses Evaluate to side-step the UDF context

    Public Function DFColor(addr)
        DFColor = Range(addr).DisplayFormat.Interior.Color
    End Function
    
    Function CFColorMatches(rng As Range, R As Long, G As Long, B As Long)
        CFColorMatches = (rng.Parent.Evaluate("DFColor(""" & rng.Address & """)") = RGB(R, G, B))
    End Function
    

    Note also you really don't need all that RGB-related code

提交回复
热议问题