Excel VBA函数根据范围中的单元格背景颜色返回真或假

Rya*_*n B 4 sorting excel function colors range

我保留了我的时间表的电子表格,当我遇到并期望达到某些里程碑时.数据(日期)从左到右存储,每个项目都有自己的行.里程碑是永久设定的并且占据范围(O:AA).我的数据颜色编码为绿色(完整),橙色(截止日期),蓝色(不工作),红色(不适用).

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

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

我想在像= ScanForColor(O3:AA3)这样的单元格中调用该函数,我将在AB列中使用ScanForColor函数来保存过滤文档的值.

Gra*_*eme 8

像这样的东西就可以了!

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
Run Code Online (Sandbox Code Playgroud)

这将允许您调用和测试不同的颜色值....