ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop Down Columns and Compare Values (https://www.excelbanter.com/excel-programming/370377-loop-down-columns-compare-values.html)

DrwRob28

Loop Down Columns and Compare Values
 
Hi,

I am trying to write a macro that will loop through columns (eg A and
B) and across the row and compare the values on the same row in
different columns and if the value in column A on that same row is
greater then I would like to highlight those cells. Is there anyone who
could help?

Thanks!


Tom Ogilvy

Loop Down Columns and Compare Values
 
set rng = Range("A1:A100")
rng.Resize(,2).Interior.ColorIndex = xlNone
for each cell in rng
if cell.Value cell.offset(0,1).Value then
cell.Resize(1,2).Interior.ColorIndex = 3
end if
Next

--
regards,
Tom Ogilvy

"DrwRob28" wrote in message
ups.com...
Hi,

I am trying to write a macro that will loop through columns (eg A and
B) and across the row and compare the values on the same row in
different columns and if the value in column A on that same row is
greater then I would like to highlight those cells. Is there anyone who
could help?

Thanks!




DrwRob28

Loop Down Columns and Compare Values
 
Thanks Tom!\


Tom Ogilvy wrote:
set rng = Range("A1:A100")
rng.Resize(,2).Interior.ColorIndex = xlNone
for each cell in rng
if cell.Value cell.offset(0,1).Value then
cell.Resize(1,2).Interior.ColorIndex = 3
end if
Next

--
regards,
Tom Ogilvy

"DrwRob28" wrote in message
ups.com...
Hi,

I am trying to write a macro that will loop through columns (eg A and
B) and across the row and compare the values on the same row in
different columns and if the value in column A on that same row is
greater then I would like to highlight those cells. Is there anyone who
could help?

Thanks!



DrwRob28

Loop Down Columns and Compare Values
 
Thanks Tom!\


Tom Ogilvy wrote:
set rng = Range("A1:A100")
rng.Resize(,2).Interior.ColorIndex = xlNone
for each cell in rng
if cell.Value cell.offset(0,1).Value then
cell.Resize(1,2).Interior.ColorIndex = 3
end if
Next

--
regards,
Tom Ogilvy

"DrwRob28" wrote in message
ups.com...
Hi,

I am trying to write a macro that will loop through columns (eg A and
B) and across the row and compare the values on the same row in
different columns and if the value in column A on that same row is
greater then I would like to highlight those cells. Is there anyone who
could help?

Thanks!



DrwRob28

Loop Down Columns and Compare Values
 
Tom,

Do you know how I can get it to skip to columns C and D, E and F,
etc.after it is doen with A and B?

Thanks,
Drew

DrwRob28 wrote:
Thanks Tom!\


Tom Ogilvy wrote:
set rng = Range("A1:A100")
rng.Resize(,2).Interior.ColorIndex = xlNone
for each cell in rng
if cell.Value cell.offset(0,1).Value then
cell.Resize(1,2).Interior.ColorIndex = 3
end if
Next

--
regards,
Tom Ogilvy

"DrwRob28" wrote in message
ups.com...
Hi,

I am trying to write a macro that will loop through columns (eg A and
B) and across the row and compare the values on the same row in
different columns and if the value in column A on that same row is
greater then I would like to highlight those cells. Is there anyone who
could help?

Thanks!



Tom Ogilvy

Loop Down Columns and Compare Values
 
Something screwy happened and an incomplete post may have been posted. use
this post

Dim rng as Range, ar as Range
set rng = Range("A1:A100,C1:C100,E1:E100")
for each ar in rng.Areas
ar.Resize(,2).Interior.ColorIndex = xlNone
for each cell in ar
if cell.Value cell.offset(0,1).Value then
cell.Resize(1,2).Interior.ColorIndex = 3
end if
Next cell
Next ar


--
Regards,
Tom Ogilvy


"DrwRob28" wrote:

Tom,

Do you know how I can get it to skip to columns C and D, E and F,
etc.after it is doen with A and B?

Thanks,
Drew

DrwRob28 wrote:
Thanks Tom!\


Tom Ogilvy wrote:
set rng = Range("A1:A100")
rng.Resize(,2).Interior.ColorIndex = xlNone
for each cell in rng
if cell.Value cell.offset(0,1).Value then
cell.Resize(1,2).Interior.ColorIndex = 3
end if
Next

--
regards,
Tom Ogilvy

"DrwRob28" wrote in message
ups.com...
Hi,

I am trying to write a macro that will loop through columns (eg A and
B) and across the row and compare the values on the same row in
different columns and if the value in column A on that same row is
greater then I would like to highlight those cells. Is there anyone who
could help?

Thanks!





All times are GMT +1. The time now is 05:17 PM.

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