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.

Beginner IF EXACT SUMPRODUCT SUM FILTER ABS

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:

D3fx=IF(B3=C3,"Match","Different")
ABCD
1ProductSystemCountedCheck
2Cable120120
3Charger4544Different
4Mouse310310
5Keyboard140138
6Headset6060
7Webcam2527

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:

E2fx=SUMPRODUCT(--(B2:B7<>C2:C7))
ABCDE
1ProductSystemCounted
2Cable1201203
3Charger4544
4Mouse310310
5Keyboard140138
6Headset6060
7Webcam2527

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

  1. Select A2:C7 with A2 as the active cell.
  2. Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format.
  3. Enter =$B2<>$C2. The $ before the column letters makes every cell in the row test columns B and C.
  4. 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. 120 and 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.
Tip. For a reconciliation where each product appears once in two separate tables, bring the second value next to the first with a lookup (=XLOOKUP(A2,Counted[Product],Counted[Qty])) and then compare. The lookup approaches are compared in Lookup guide: VLOOKUP vs INDEX/MATCH vs XLOOKUP.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 14 KB

More how-to recipes