我试图在 excel 中显示条件格式的颜色。 例如,在 excel 中,我只是使用 =CheckColour(B5),当我点击返回时,它就起作用了。但是,当我要求工作表进行计算时,该函数给出了#VALUE!而且我不知道我哪里出错了。感谢您的帮助,因为我是 VBA 的初学者。谢谢
Function CheckColour(range)
If range.DisplayFormat.Interior.Color = RGB(255, 0, 0) Then
CheckColour = "Red"
ElseIf range.DisplayFormat.Interior.Color = RGB(0, 130, 59) Then
CheckColour = "Green"
Else
CheckColour = "Amber"
End If
End Function
最佳答案
是的,因为:
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. Ref.
改为使用:
range.Interior.Color
关于VBA 代码返回#value 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42094225/