VBA Excel Function: Detect if any cell in a range has sepecific background color

 VBA Excel Function: Detect if any cell in a range has sepecific background color 


Function BGColor(targetColorCell As Range, rnge As Range) As Boolean
Dim result As Boolean, targetColor As String, obColor As String
targetColor = Hex(targetColorCell.Interior.Color)
result = False
For Each cell In rnge
obColor = Hex(cell.Interior.Color)
If obColor = targetColor Then
result = True
Exit For
End If
Next cell
BGColor = result
End Function

0 Comments