I am new to the VBA Function and I wrote a very simple function to test if the background of a cell is filled with a particular color. However, the return value is always #VALUE!. It should be a very simple mistake but still can’t find where the problem is after I tried different methods to fix it. I attached the code I wrote below. Can anybody help me with my problem?
Function SAFETY(Cell As Range) As Boolean Application.Volatile If (Cell.DisplayFormat.Interior.Color = 7040761) Then SAFETY = True Else SAFETY = False End If End Function
I checked the formula with the Insert Function section under Formulas Tab, the return value is actually TRUE. However, it just cannot displayed on the worksheet cell. enter image description here