Loop Column Compare

pvans267

New Member
Joined
Feb 25, 2010
Messages
35
Good afternoon,

I wonder if someone would be able to help me with an issue that I am having.

I have two worksheets in a workbook.

Each row in Column C contains values on either sheet that are sometimes different, and sometimes are the same:

Example:
Sheet1 Sheet2
C C
1 1
2 3
3 2
2 2
5 2


I am trying to create a macro to compare each row in column C on sheet1 and sheet2. And total the results be displayed in cells C2 - C4on Sheet 3. C2 represents "matching", C3 represents "Sheet1 Bigger", C4 represents "Sheet1 Smaller"<SHEET2"< p>
Therefore, the results for the simple example above would appear like so:
Sheet3
C
2
2
<SHEET2 p 1<>1

One final point (as if this wasn't tricky enough :(), occasionally a row will have no data - in either sheet - for column C, and so I would like that row to be ignored and not be included in the "matching" result.

I am clueless as to where to start and would be very grateful if someone could help me.

Thank you,

Paul
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi Paul,

Do you have to use a macro? A formula may be sufficient - try the following array formulae in cells C2 to C4 of Sheet3 (enter them using CTRL-SHIFT-ENTER rather than just ENTER):

C2:
=SUMPRODUCT((Sheet1!$C$1:$C$5=Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>"")*(Sheet2!$C$1:$C$5<>""))

C3:
=SUMPRODUCT((Sheet1!$C$1:$C$5>Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>"")*(Sheet2!$C$1:$C$5<>""))

C4:
<?XML:NAMESPACE PREFIX = Sheet2!$C$1 /><Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<><Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<><Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<><Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<><Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>(for some reason this formula with less than doesn't show up properly here - its exactly as per the one in C3, just replace the first > with a less than)</Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<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heet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<></Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<></Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<></Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<></Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>
<Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<><Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<><Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<><Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<><Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>Here, the first array checks for the condition (=,> or<), and the second and third ensure that blanks are skipped. You would change the ranges to whatever rows in column C you need to compare.
</Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>
</Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>
</Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>
</Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>
</Sheet2!$C$1:$C$5)*(Sheet1!$C$1:$C$5<>
 
Last edited:
Upvote 0
Thank you very much. Seems to work very nicely

Gonna play around with it a little more to complete testing but seems to be perfect.

Thank you so much

Paul
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

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