How to compare two Excel sheets with rows in a different order
29 November 2026
When the rows in two Excel sheets are in a different order, don't compare them cell by cell. Match each row by something that identifies it, such as an invoice number, SKU or employee number, using XLOOKUP, or INDEX and MATCH in older versions. Then check the other way round to find rows that were removed. If no single column is unique, join two columns into a helper key and match on that.
The examples use two sheets in one workbook called Old and New, with an ID in column A, data in columns B to D, and headings in row 1. To bring in a sheet from another file, right-click its tab, choose Move or Copy, pick the workbook and tick Create a copy.
Why cell-by-cell comparison fails
A formula like =Old!B2<>New!B2 compares positions, not records. If the new version was sorted by name instead of by date, row 2 now holds a different customer, and nearly every row shows as changed. The same happens when one row is inserted or deleted: every row below it is out by one.
1. Sort both sheets by the same column
Good for: two sheets with exactly the same rows, just in a different order.
- Click any cell in the data on the Old sheet.
- Choose Data > Sort, tick My data has headers, and sort by the ID column.
- Do exactly the same on the New sheet.
- Compare cell by cell, as in our guide to comparing two Excel files.
Work on copies, and watch for three things:
- Sort the whole table. If you select one column and sort it, Excel offers to expand the selection. Accept, or that column's values get separated from the rest of each row.
- Missing or extra rows. Sorting fixes the order, not the count. One extra row and everything after it is out of line again.
- Duplicate IDs. Rows that share an ID can end up in a different order in each sheet. Use Add Level in the Sort dialog to add a second column as a tie-breaker.
2. Match rows by a unique ID with XLOOKUP
Good for: rows that were added, removed and re-sorted, where each row has a unique ID.
Look each ID up in the other sheet. On the New sheet, in column E, enter this to check whether column C changed, and fill it down:
=LET(old, XLOOKUP($A2, Old!$A:$A, Old!C:C, "Not in old"), IF(old="Not in old", "Added", IF(old<>C2, "Changed from "&old, "")))
Each row shows "Added" if its ID isn't on the old sheet, "Changed from" and the old value if column C is different, or nothing if it matches, wherever the row sits. Fill it right to check the next column.
To check every column at once, compare the whole row. This assumes both sheets have the same columns in the same order:
=IF(ISNA(XMATCH($A2, Old!$A:$A)), "Added", IF(AND(XLOOKUP($A2, Old!$A:$A, Old!$B:$D)=B2:D2), "", "Changed"))
Then go the other way. These formulas only look at rows in the new sheet, so they can't see deleted rows. On the Old sheet, in column E:
=IF(ISNA(XMATCH($A2, New!$A:$A)), "Removed", "")
XLOOKUP, XMATCH and LET need Microsoft 365 or Excel 2021 or later. In older versions, use MATCH and INDEX on the New sheet, and on the Old sheet replace XMATCH($A2, New!$A:$A) with MATCH($A2, New!$A:$A, 0):
=IF(ISNA(MATCH($A2, Old!$A:$A, 0)), "Added", IF(INDEX(Old!C:C, MATCH($A2, Old!$A:$A, 0))<>C2, "Changed", ""))
3. No unique ID? Build a key from two columns
Good for: timesheets, order lines and other lists where a row is only unique by a combination, such as employee and date.
Add a helper column to both sheets that joins the columns. If the order number is in A and the product code in B, enter this in the first empty column of each sheet and fill it down:
=A2&"|"&B2
The separator matters. Without it, order 12 with product 3 and order 1 with product 23 would both become 123. Then use the formulas from method 2, with the helper column as the lookup column instead of column A.
- Choose columns that don't change. If the key includes a value that was edited, such as a quantity, the row no longer matches its old self. It shows up as removed and added, rather than changed.
- Dates become numbers. Joining a date gives its serial number, such as 46000. That still matches if both sheets hold real dates rather than text. Use
TEXT(B2, "yyyy-mm-dd")in the key if you want it readable.
4. Deal with duplicate keys
Good for: checking your key before you trust any of the above.
XLOOKUP and MATCH return the first match only. If an ID appears twice, both copies are compared with the same row in the other sheet, which can hide a real change. Check each sheet first:
=COUNTIF($A:$A, A2)>1
TRUE means the key appears more than once. Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values shows the same thing. Then:
- If they're accidental duplicates, ask whoever produced the file, or remove them on a copy with Data > Remove Duplicates.
- If they're different records, such as several lines on one invoice, add another column to the key, as in method 3.
- If nothing tells them apart, number each occurrence with
=A2&"|"&COUNTIF($A$2:A2, A2), so the first INV-1001 becomes INV-1001|1 and the second INV-1001|2. This only works if the repeated rows are in the same order in both sheets.
When it's easier to use a tool
Each formula checks one column in one direction, so a full check of a wide sheet means a formula per column, both ways round.
Compare Sheets does the matching for you. It lines up inserted, deleted and moved rows automatically, or pairs rows by an ID column you choose, wherever they are. It shows each changed cell with its old and new value, and any added or removed columns. It reads .xlsx, .xlsm, .csv and .tsv files and runs in your browser on Windows or Mac, so the files never leave your computer. The free version compares the first 1,000 rows of each sheet, and you can try it with sample files.
Quick answers
Why does every row show as changed? The rows are probably in a different order, or a row was inserted near the top. Match rows by an ID instead of by position.
Can I compare two sheets without a unique ID? Yes. Join two or more columns into a helper key with =A2&"|"&B2 and match on that, or use a tool that lines up rows automatically.
Is sorting both sheets enough? Only if both contain exactly the same rows and every key is unique. Otherwise they fall out of line again.