Compare Two Rows

S

smandula

Can anyone provide a VBA macro?
To compare two rows of values, if the lower row value equals
the upper row value color both values green.
Need this across 70 columns

Example:

Row 1 0 1 4 4 5 6 7
Row 2 4 4 8 4 9 0 8

4 in Row 1 & Row 2 would be highlited

With Thanks
 
D

dolivastro

First select the data you want compared. Then use this script:

dim r as long
dim c as long

for r = 1 to selection.rows.count
if (selection.cells(r,1).value = selection.cells(r,2).value) then
for c = 1 to 2
selection.cells(r,c).interior.colorindex = 3
selection.cells(r,c).interior.pattern=xlSolid
next c
end if
next f


Hope this helps
Dom
 
B

Bernard Liengme

No need for a macro; can be done using Format | Conditional Formatting with
Formula is =A2=A3
best wishes
 
C

CLR

What you desire can be easily accomplished with the Excel feature called
Conditional Formatting......no macro required.
First, highlight cells A1 and A2, then do Format > ConditionalFormat > then
in the left window select "Formula is" and in the right window type the
formula
=AND(SUM(A$12:A$13)>0,A$12=A$13), then select the Format button on the
pop-up and choose the Patterns Tab, and click on a Green square, then ok >
ok, Then, highlight the same two cells and select the FormatPainter icon in
the upper toolbar, (the little paintbrush), and drag it across all the cells
you wish to format the same.......ie, your 70 columns. This will make the
cells turn green if they are matching in value and ARE NOT ZERO, OR
EMPTY.......

hth
Vaya con Dios,
Chuck, CABGx3
 
B

Bruno

There is the mistake in the formula:
A$12 should be A$1, and A$13 sholud be A$2. I also tried it and after I
corrected cell references it works perfectly.
Bruno
 
C

CLR

Good "catch" Bruno.........I did my testing a little further down the sheet
and forgot to convert when I posted........

Vaya con Dios,
Chuck, CABGx3
 
S

smandula

Thanks for all your relies.

However, I was hoping for a VBA solution.

With Thanks
 
L

Lars

Created a VBA solution myself.

Thanks for Looking, to all respondents

I think you should share your solution with us!
That is was Usenet is all about.


Lars
Stockholm
 
Top