Avatar of Imran Asif
Imran Asif
 asked on

Compare 2 excel spreadsheets and highlight the differences

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.
Microsoft ExcelOffice Productivity

Avatar of undefined
Last Comment
Imran Asif

8/22/2022 - Mon
Steven Harris

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.
Glenn Ray

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
Glenn Ray

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?
Your help has saved me hundreds of hours of internet surfing.
fblack61
Steven Harris

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.
Imran Asif

ASKER
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
Glenn Ray

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Imran Asif

ASKER
Hi Glenn:

Here is the sample data file.

Thanks,
Sample-data.xlsx
Imran Asif

ASKER
Hi Glenn:

Any solution yet?

Thanks,
ASKER CERTIFIED SOLUTION
Glenn Ray

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Imran Asif

ASKER
Perfect
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes