Excel VBA函数根据范围内的单元格背景颜色返回True或False

我在工作时间和时间表上保存了一个电子表格,当我遇到并期望遇到某些里程碑时。 数据(date)从左到右存储,每个项目都有自己的行。 里程碑是permantely设置和占领范围(O:AA)。 我的数据颜色编码为绿色(完整),橙色(截止date),蓝色(不工作),红色(不适用)。

我想要做的是写一个函数,检查一个单元格是否包含橙色背景(颜色索引6),并返回TRUE或FALSE。 基本上我想汇总所有列的所有截止date。 最后,我想整合一个date检查,所以我可以看到哪些截止date即将到来。

Function ScanForColor(Dates As Range) as Boolean If ScanForColor.Interior.ColorIndex = 6 Then ScanForColor = True Else ScanForColor = False End Function 

我想调用像= ScanForColor(O3:AA3)的单元格中的函数,我将AB栏中的ScanForColor函数来保存过滤文档的值。

像这样的事情会做的伎俩!

 Function ScanForColor(Cells As Range, ColorValue As Integer) As Boolean Dim cell As Range For Each cell In Cells If cell.Interior.ColorIndex = ColorValue Then ScanForColor = True Exit For End If Next End Function 

这将允许你打电话和testing不同的颜色值….