Compare excel sheets using VBA

druff

New Member
Joined
Jul 23, 2012
Messages
2
Hello All,

I have spent a few days looking around the internet for an answer to my question, but no luck. I am trying to compare sheet 'Base_Mach' to 'Comp_Mach' and create a new sheet with the results. I have found threads on how to do this, but there is another twist to what I am trying to accomplish. Here's a quick example of two databases and how I need to compare them:

Base_Mach:[TABLE="width: 500"]
<TBODY>[TR]
[TD]MachineId
[/TD]
[TD]LoopId
[/TD]
[TD]Phases
[/TD]
[TD]AutoMode
[/TD]
[/TR]
[TR]
[TD]8433
[/TD]
[TD]1
[/TD]
[TD]2
[/TD]
[TD]True
[/TD]
[/TR]
[TR]
[TD]8433
[/TD]
[TD]3
[/TD]
[TD]3
[/TD]
[TD]True
[/TD]
[/TR]
[TR]
[TD]8433
[/TD]
[TD]4
[/TD]
[TD]3
[/TD]
[TD]False
[/TD]
[/TR]
</TBODY>[/TABLE]

Comp_Mach:[TABLE="width: 500"]
<TBODY>[TR]
[TD]MachineId
[/TD]
[TD]LoopId
[/TD]
[TD]Phases
[/TD]
[TD]AutoMode
[/TD]
[/TR]
[TR]
[TD]3584
[/TD]
[TD]1
[/TD]
[TD]3
[/TD]
[TD]False
[/TD]
[/TR]
[TR]
[TD]3584
[/TD]
[TD]2
[/TD]
[TD]3
[/TD]
[TD]False
[/TD]
[/TR]
[TR]
[TD]3584
[/TD]
[TD]3
[/TD]
[TD]3
[/TD]
[TD]True
[/TD]
[/TR]
[TR]
[TD]3584
[/TD]
[TD]4
[/TD]
[TD]2
[/TD]
[TD]False
[/TD]
[/TR]
</TBODY>[/TABLE]

The problem I am having is that I want to compare these two tables (both are sorted by LoopId), and need to compare LoopId 1 to LoopId 1, LoopId 2 to LoopId 2, etc. If there is no '2' like in the above example, I'm hoping to skip that row and make a note that it does not exist in that row. Then continue the comparison by doing 3 vs 3 and 4 vs 4...

The result would be something along the lines of:

Results:
[TABLE="width: 500"]
<TBODY>[TR]
[TD]LoopId
[/TD]
[TD]Phases
[/TD]
[TD]AutoMode
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]diff
[/TD]
[TD]diff
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]N/A
[/TD]
[TD]N/A
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]same
[/TD]
[TD]same
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]diff
[/TD]
[TD]same
[/TD]
[/TR]
</TBODY>[/TABLE]


I am able to compare all of the cells in one sheet versus the other sheet but if there is a machine that does not have 1 or more loops, the whole comparison is thrown off.

I would really appreciate any help!!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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