Change row colour dependant on criteria

AyKay86

New Member
Joined
Feb 14, 2008
Messages
20
Hi guys & girls,

I need to get a row to highlight if one cell has a difference compared to another. The coding below works for the first cell, but others in the sequence do not change. I know the Range("A5:Z5") is wrong, but the loop is not working either, it's running the If statement even if the date in R7 is today.

For Each c In Range("R5:R10")
If c.Text < "Today()" Then
Range("A5:Z5").Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next c

Any and all help appreciated.

Thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Code:
    For Each c In Range("R5:R10")
        If c.Value < Date Then
            With c.Interior
                .ColorIndex = 3
                .Pattern = xlSolid
            End With
        End If
    Next c
 
Upvote 0
That works, thanks very much. I've now been asked whether I can get it to look at column A for each row rather than the date. Instead of saying:

For Each c In Range("R5:R10")
If c.Value < Date Then
With c.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next c

I need it say something like:

For Each c In Range("R5:R10")
If c.Value < Range("A5") Then
With c.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next c

I know the red line won't work because it will compare everything with A5, but I was wondering if there is a way to get it to look at column A for each row?

Thanks
 
Upvote 0
Code:
    For Each c In Range("R5:R10")
        If c.Value < Cells(c.Row, "A").Value Then
            With c.Interior
                .ColorIndex = 3
                .Pattern = xlSolid
            End With
        End If
    Next c
 
Upvote 0

Forum statistics

Threads
1,203,615
Messages
6,056,307
Members
444,858
Latest member
ucbphd

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