Multiple Column Cell Compare looping through Rows

N

nickg420

Hi I have a problem...... I need to compare 3 cells of data in
different columns D, E, and F. And Change the color of said cell t
Red if it is higher than the Cell in Column D and Green if it is Lowe
than the cell in column D. I need to do this for every row in th
worksheet starting with row 2.

I have this all worked out on paper but can't seem to get the synta
right. Keep in mind I'm more used to VB.Net than VBA and I'm learnin
as I go certain things just don't fly in VBA. Any amount of help woul
be greatly appreciated.

Thanks N
 
T

Tom Ogilvy

Dim rng as Range, cell as Range
Dim i as Long
set rng = Range(Range("D2"),Cells(rows.count,4).End(xlup))
for each cell in rng
for i = 1 to 2
if cell.offset(0,i).Value < cell.Value then
cell.offset(0,i).Interior.ColorIndex = 4
elseif cell.offset(0,i).Value > cell.Value then
cell.offset(0,i).Interior.ColorIndex = 3
end if
Next i
Next cell
 
J

JulieD

Hi Nick

if i'm understanding you correctly i would use conditional formatting for
this - select from E2 to the end of the numbers in column E choose
Format / Conditional formatting
choose
formula is
and type
=$E2>$D2
click on the format button and choose Red - click OK

then click the ADD button
choose
formula is
and type
=$E2<$D2
click on the format button and choose Green - click OK, click OK again

repeat for column F (starting at F2)

Hope this helps
Cheers
JulieD
 
Top