?
Solved

Compare 2 excel spreadsheets and highlight the differences

Posted on 2014-08-05
10
Medium Priority
?
1,187 Views
Last Modified: 2014-08-07
Hi Experts:

I have an excel file with 2 sheets.  There are 10 columns in each sheet.  Columns in Sheet 1 and Sheet 2 are the same but the data is slightly different.  

Is it possible to compare the 2 sheets and highlight the rows or cells with a difference?  Is it possible to reach to a solution without a VBA or vbscript?  Is it possible to reach to a solution using vlookup or match or conditional formatting?

Thanks in advance.
0
Comment
Question by:Imran Asif
  • 4
  • 4
  • 2
10 Comments
 
LVL 18

Expert Comment

by:Steven Harris
ID: 40242580
Although it is easier with VBA, you can still use Conditional Formatting:

Select the first cell of Sheet 1 (A1) > Conditional Formatting > Use Formula:

=$A1<>Sheet2!$A1

This looks at Sheet1 cell A1 and if it is not the same as Sheet2 cell A1 then it will perform the formatting.  Apply formatting of your choice (cell fill, text font, etc.) and apply to workbook.

Fill down formatting to all cells in that column.  Rinse and repeat for each column, exchanging the $A1 for $B1, etc.

This applies formatting to Sheet 1 only, and will have to be repeated for Sheet 2 if you want to see highlighting there as well.
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40242679
Here's a sort-of quick-and-dirty solution; anything more elaborate will probably require VBA.

This example has two source sheets - Sheet1 and Sheet2 - and the data ranges from columns A through H.  This is only eight columns, but you could change the methods/formulas to extend to column J (ten columns).

1) Create a new sheet with the same header/column layout as your source sheets.  For example, I'm naming it "Common"
2) Insert the following formula in cell A2 and copy across and down as many rows as in Sheet1.
=IFERROR(VLOOKUP(Sheet1!A2,Sheet2!A:$H,1,FALSE),"")
You will see all the common values in both sheets, regardless of record location.

3) Add a new column to the right, label the top cell "Duplicate" and add this formula in row 2 and copy down:
=IF(SUMPRODUCT(--((A2:H2)=""))=0,"Yes","No")
This will show "Yes" or "No" if the row has full matches and is therefore a duplicate in both Sheet1 and Sheet2

4) Turn on data filtering and filter on the "Yes" values to simplify the sheet.

I've attached an example file that demonstrates this.  I'm still trying to develop a simple conditional formatting method to apply to the first sheet that will highlight values if there are no unique keys (i.e., the entire row vs. a unique field).

Regards,
-Glenn
EE-DuplicateRowsAcrossSheets.xlsx
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40242680
TSS:  What if the duplicate values on Sheet2 are in a different row?  Won't the conditional formatting rule fail after the first mis-match of common rows?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Steven Harris
ID: 40242798
Glenn, you are correct, but was working based off of the OP's comment of "Columns in Sheet 1 and Sheet 2 are the same  but the data is slightly different."

I took this to mean that we would be comparing the same cells across sheets, i.e. Sheet 1 cell A1, to Sheet 2 cell A1, and so on.
0
 

Author Comment

by:Imran Asif
ID: 40242819
Hi Glenn:

Thanks for the solution.  I am working on it to see if it works in my case.  I think I have blank spaces in the cells.  Can we use TRIM function in your formula?

Also it will be very helpful if we can highlight the differences in different worksheet.

Thanks
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40242835
If your data is "slightly different" due to extra spaces, I think it would be important to see that.  Otherwise, you should trim all the data on the suspect table before running the real comparison.

An example file with just a few rows of data would really help us provide an adequate solution.

-Glenn
0
 

Author Comment

by:Imran Asif
ID: 40244217
Hi Glenn:

Here is the sample data file.

Thanks,
Sample-data.xlsx
0
 

Author Comment

by:Imran Asif
ID: 40246506
Hi Glenn:

Any solution yet?

Thanks,
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 2000 total points
ID: 40247549
I tried my "quick and dirty" solution above and it appears to work; did you have issues?

The data can't be checked on a per-row basis for two reasons:
1) The data isn't sorted; two different amount values for the same person could be swapped on adjacent rows.  While this is literally a difference, taken as a set, it is not and one would not want to see any highlighting.
2) Extra data exists in Sheet1 that is not in Sheet2.  This would prevent sorting of data if one were to do a per-row check (as I noted previously with ThinkSpaceSolution's suggestion).

See the example file; I added a conditional formatting rule that highlights the entire row of data on Sheet1 if the "Duplicate" value on the "Common" sheet is "Yes."

Note:  If your Sheet1 has two rows for the same individual with different amounts (ex., 100 and 96) and Sheet2 has both of those values also, neither row will not be highlighted even if one value is changed to match the other.  For example, change cell E5 on sheet1 to 100 or 96; it won't highlight because both of those values exist for that person on the other sheet.

-Glenn
EE-Sample-Data.xlsx
0
 

Author Closing Comment

by:Imran Asif
ID: 40247613
Perfect
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question