Excel VBA function to return True or False based on cell background colors in a range

I keep a table of my timelines at work and when I meet and expect you to meet certain stages. Data (dates) are stored from left to right, and each project has its own line. Milestones are predefined and occupy a range (O: AA). My data is color coded as green (full), orange (deadline), blue (not working), red (not applicable).

I would like to write a function that checks if the cell contains an orange colored background (Color index 6) and returns TRUE or FALSE on it. Basically I want to combine all the deadlines for all columns. In the end, I would also like to integrate date validation to see which deadlines are approaching.

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

I would like to call a function in a cell of type = ScanForColor (O3: AA3), and I will have a ScanForColor function in column AB to store the values โ€‹โ€‹for filtering the document.

+3
source share
1 answer

Something like this will do the trick!

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

This will allow you to call and test different color values โ€‹โ€‹....

+6
source

Source: https://habr.com/ru/post/1756964/


All Articles