Link to home
Start Free TrialLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

Check whether selected cells contain a certain fill color

Dear Experts,

for the selected cells (see below) I would like to check, whether none of the selected cells have a RGB fill of 235, 219, 218.

If none of the selected cells contain this specific cell fill 'RGB 235, 219, 218', a msgbox has to tell the user that this is the case, else do nothing.

Range(Selection, Selection.End(xlDown)).Select

Open in new window


Help is much appreciated.

Thank you very much in advance.

Regards, Andreas
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try
Sub macro()
Set Rng = Range(Selection, Selection.End(xlDown))
bfound = False
For Each c In Rng
    If c.Interior.Color = RGB(235, 219, 218) Then
        bfound = True
        Exit For
    End If
Next
If Not bfound  Then MsgBox "None of the cells has the required color"
End Sub

Open in new window

if you want to se the select cells then
Sub Macro()
Range(Selection, Selection.End(xlDown)).Select
bfound = False
For Each c In Selection
    If c.Interior.Color = RGB(235, 219, 218) Then
        bfound = True
        Exit For
    End If
Next
If Not bfound Then MsgBox "None of the selected cells has the required color"
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andreas Hermle

ASKER

Hi Rgonzo, thank you very much for your swift help. Will test the solutions as soon as possible.

Regards, Andreas
Great, this did the trick, thank you very much for your professional help. Regards, Andreas