How-to recipes · Analysis
How to compare two columns in Excel
Compare two columns row by row: show Match or Different, count the differences, colour them, and do a case-sensitive check with EXACT.
A stock count: column B holds the quantity the system thinks you have, column C holds what the team actually counted on the shelf. Or a price list before and after an update, or two versions of the same report. You want to know, row by row, where the two columns disagree, how many rows differ, and ideally have the differences jump out in colour. Comparing two columns in the same row is one of the most common checks in Excel, and every version can do it with simple formulas.
The example data
Six products in A2:A7 with the system quantity in B and the counted quantity in C. Charger, Keyboard and Webcam do not agree.
Step 1: a Match / Different column
In D2 compare the two cells with = and let IF turn the TRUE/FALSE into readable words, then copy down to D7:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Product | System | Counted | Check |
| 2 | Cable | 120 | 120 | |
| 3 | Charger | 45 | 44 | Different |
| 4 | Mouse | 310 | 310 | |
| 5 | Keyboard | 140 | 138 | |
| 6 | Headset | 60 | 60 | |
| 7 | Webcam | 25 | 27 |
Charger: the system says 45, the shelf has 44.
Result: Different
The comparison B3=C3 on its own returns TRUE or FALSE, which is enough for filtering. For numbers you may also want the size of the gap: =C3-B3 shows -1 (one charger missing), and =ABS(C3-B3) shows the gap without a sign using ABS.
Step 2: count the differences
In Microsoft 365 the comparison of two ranges returns an array, so you can count mismatches in one cell: =SUM(--(B2:B7<>C2:C7)). The -- turns TRUE/FALSE into 1/0. In Excel 2016 and 2019, SUM would need Ctrl+Shift+Enter, so use SUMPRODUCT, which works in every version:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Product | System | Counted | ||
| 2 | Cable | 120 | 120 | 3 | |
| 3 | Charger | 45 | 44 | ||
| 4 | Mouse | 310 | 310 | ||
| 5 | Keyboard | 140 | 138 | ||
| 6 | Headset | 60 | 60 | ||
| 7 | Webcam | 25 | 27 |
Three rows differ.
Result: 3
Microsoft 365 can also list the products that differ, with no helper column: =FILTER(A2:A7,B2:B7<>C2:C7) spills Charger, Keyboard and Webcam. See FILTER.
Step 3: colour the rows that differ
- Select A2:C7 with A2 as the active cell.
- Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format.
- Enter
=$B2<>$C2. The$before the column letters makes every cell in the row test columns B and C. - Choose an orange fill and click OK.
Any row where the counts disagree is now orange, and fixing the number removes the colour. More on formula rules in Conditional formatting, including formula-based rules.
Keyboard shortcut for a one-off check
Select B2:C7 and press Ctrl+\ (Home > Find & Select > Go To Special > Row differences). Excel selects the cells in column C that differ from column B in the same row. Give them a fill colour straight away; the selection is not kept.
Case-sensitive comparison
The = operator ignores case: ="abc"="ABC" is TRUE. When case matters, such as passwords, product codes or IDs in a case-sensitive system, use EXACT: =IF(EXACT(B2,C2),"Match","Different"). EXACT also catches a difference in spaces, but so does =.
Pitfalls
- Numbers stored as text.
120and the text"120"are not equal, even though they look identical. If everything says Different, check with=ISTEXT(C2)and convert the text numbers (select the column, Data > Text to Columns > Finish). - Hidden decimals. A cell showing 60 may contain 59.999 after a calculation. Compare rounded values:
=ROUND(B2,2)=ROUND(C2,2). - Extra spaces. Text imported from other systems often has trailing spaces. Use
=TRIM(B2)=TRIM(C2)or clean the data first (How to remove spaces in Excel). - Different order. This recipe compares row 2 with row 2. If the lists are in a different order, you are really asking whether a value exists anywhere in the other list: see How to find duplicates between two lists in Excel.
=XLOOKUP(A2,Counted[Product],Counted[Qty])) and then compare. The lookup approaches are compared in Lookup guide: VLOOKUP vs INDEX/MATCH vs XLOOKUP.