ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiple Column Cell Compare looping through Rows (https://www.excelbanter.com/excel-programming/305736-multiple-column-cell-compare-looping-through-rows.html)

nickg420[_7_]

Multiple Column Cell Compare looping through Rows
 
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

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Multiple Column Cell Compare looping through Rows
 
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

--
Regards,
Tom Ogilvy

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

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

Thanks NG


---
Message posted from http://www.ExcelForum.com/




JulieD

Multiple Column Cell Compare looping through Rows
 
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


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

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

Thanks NG


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 12:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com