首页 > 解决方案 > 如何检索条件格式单元格的背景颜色?

问题描述

我正在尝试查找有条件格式化的单元格的背景颜色。定义的功能代码如下,如果我手动为单元格着色,它可以工作,但如果应用条件格式,它会返回一个代码,就像单元格具有标准的白色背景一样。

我正在尝试使用此功能来应用基于该背景颜色的附加条件格式。

Function IdentifyColor(CellToTest As range)

'Returns R + (256 * G) + (65536 * B)
'IdentifyColor = 255 for red, 65280 for green, etc.
IdentifyColor = CellToTest.Interior.ColorIndex

End Function

这是带有手动和条件格式单元格以及返回值的工作表的样子:

颜色格式

标签: excelvbauser-defined-functionsconditional-formatting

解决方案


推荐阅读