Color if color..

emukiss10

Board Regular
Joined
Nov 17, 2017
Messages
201
Hello,

simple one :)

if color of any cell in range lastRow col A, columns A:P is not white than color every white cells in this row in this range to RGB(157,157,157).


I'd like to color every white cell from column A to column P to grey but do not touch red colored cells only if red cell(s) is(are) found..

for every cell in range
if any cell in range <> rgb(255,255,255) than
for every cell = rgb(255,255,255) in range
Cells(?,?).Interior.Color = RGB(157, 157, 157)

something like that..

Best regards
W.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Perhaps:

Code:
Sub test()
Dim c As Range
For Each c In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    If c.Interior.Color <> vbWhite And c.Interior.Color <> vbRed Then
        Cells(c.Row, "P") = c
        Cells(c.Row, "P").Interior.Color = RGB(157, 157, 157)
    End If
Next
End Sub
 
Last edited:
Upvote 0
It does nothing..

Ive chceked it on new wb and it does nothing. Something is wrong.

if any cell in range A:P is not white then it should colour every white cell in the same range.
 
Upvote 0
Mayby I wosn't clear.

I have data sheet filled from column A to column P
some of the cells in whole sheet has interior color.
I need to search entire WB for colored cells and if non white cell is found then color row from A to P to gray BUT do not color non white cells.
 
Upvote 0
ok, Ive done it. Little around but it works. Little shorter range but concept is the same.

Please remove my provious posts (we do not like spam) or the whole thread if its not helpful.

Code:
  Dim LstRw2 As Long, ThsRw2 As Long
        
        LstRw2 = Cells(Rows.count, "A").End(xlUp).row
        
        For ThsRw2 = 2 To LstRw2
                If Cells(ThsRw2, "B").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "C").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "D").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "E").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "F").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "G").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "H").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "I").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "J").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "K").Interior.Color <> RGB(255, 255, 255) Or _
                Cells(ThsRw2, "L").Interior.Color <> RGB(255, 255, 255) _
                Then
                Cells(ThsRw2, "A").Interior.Color = RGB(157, 157, 157)
                End If
        Next ThsRw2

Scott Huish Thank You for Your Help.

Best Regards!
W.
 
Upvote 0
That doesn't address your red exception.

If you no longer want that, my code can be changed to this. Looping through the range eliminates the need for all those Or statements.

Code:
Sub test()
Dim c As Range
For Each c In Range("B2:L" & Range("A" & Rows.Count).End(xlUp).Row)
    If c.Interior.Color <> vbWhite Then c.Interior.Color = RGB(157, 157, 157)
Next
End Sub
 
Last edited:
Upvote 0
Hello, Sorry for the delay. I was ill and out of office. Can you modify these codes a little?
If you find non white cells in row, color every white cell to RGB(157, 157, 157) in range A:L of that row.

I mean, I need to mark rows with errors (non white cells in my case) by coloring grey other cells in that row. But not entire row. Just in range A:L

Im trying to refactor it myself but it's too complicated for me.


 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top