How to Compare Two Columns in Excel for Duplicates

Find codes that appear in both columns even when their rows do not line up. Flag each source row and keep its order and repeats. A value repeated only within one list is a different kind of duplicate.

Exact answer

With List A in A2:A7 and List B in B2:B7, enter =COUNTIF($B$2:$B$7,A2)>0 in C2 and fill C2:C7. TRUE means that A-row’s code appears anywhere in List B. For the reverse direction, enter =COUNTIF($A$2:$A$7,B2)>0 in D2 and fill D2:D7. Keep both source columns unchanged.

On this page8
▤Annotated stepsExcel
1

On a spare sheet, paste the six-row sample into A1, including the two headers. Leave C and D empty. Enter A in B? in C1; if you also want the reverse check, enter B in A? in D1.

2

Enter =COUNTIF($B$2:$B$7,A2)>0 in C2. The dollar signs keep the whole B2:B7 lookup range fixed while A2 changes for each source row.

3

Fill C2:C7. Compare the six flags with the first result table: only C2 and C4 should be TRUE.

4

Optionally enter =COUNTIF($A$2:$A$7,B2)>0 in D2 and fill D2:D7. This checks each B value against all of List A; D2, D3 and D5 should be TRUE.

5

Read the flags beside the original codes. Keep both C200 rows in A and both C300 rows in B; the formulas do not remove or collapse records.

Check matches across two unordered code lists

Paste the sample into A1 on a spare sheet. The header and six data rows occupy A1:B7. Put the first formula in C2 and fill to C7; use D2:D7 only if you want the reverse check. Keep the original row order.

Paste sample data starting at A1

C2: is this A code anywhere in B?

=COUNTIF($B$2:$B$7,A2)>0

D2: is this B code anywhere in A?

=COUNTIF($A$2:$A$7,B2)>0
C2:C7: each A code checked against B2:B7
Source cellCodeCOUNTIF countExpected flag
A2C1001TRUE
A3C2000FALSE
A4C3002TRUE
A5C2000FALSE
A6C4000FALSE
A7C5000FALSE

If columns are cut off, scroll the table sideways.

Optional D2:D7: each B code checked against A2:A7
Source cellCodeCOUNTIF countExpected flag
B2C3001TRUE
B3C1001TRUE
B4C6000FALSE
B5C3001TRUE
B6C7000FALSE
B7C8000FALSE

If columns are cut off, scroll the table sideways.

  • C2:C7 returns TRUE, FALSE, TRUE, FALSE, FALSE, FALSE. The two matching A rows contain C100 and C300.
  • D2:D7 returns TRUE, TRUE, FALSE, TRUE, FALSE, FALSE. Both C300 rows in B remain visible and receive their own flags.
  • C200 occurs twice in A but never in B, so both of its A-row flags remain FALSE.
  • The COUNTIF count for A4 is 2. The formula’s >0 comparison produces one TRUE in C4, not two output rows.
  • Both source lists still have six data rows. This example uses nonblank text codes without wildcard characters and performs no row deletion.

Documentation reviewed .

Microsoft: Use COUNTIF in ExcelGoogle: COUNTIF in Sheets

=COUNTIF($B$2:$B$7,A2)>0

Excel for Windows: Enter the shared-code formula in C2 and fill through C7. Keep A:B unchanged; use D2:D7 for the optional reverse check.Excel for Mac: Enter the shared-code formula in C2 and fill through C7. Keep A:B unchanged; use D2:D7 for the optional reverse check.

What this does

Here, a duplicate across two columns means a value occurs in both lists, not necessarily on the same worksheet row. COUNTIF counts occurrences in the other list, and >0 turns that count into TRUE or FALSE. The helper returns one flag for every source row. It does not produce a deduplicated list or delete any data. Repeating C200 twice in List A does not make it a cross-list match when C200 never appears in List B.

A worked example

The two shared codes are C100 and C300. C100 in A2 appears once in B; C300 in A4 appears twice in B, so its COUNTIF count is 2 but C4 still contains just one TRUE flag. The reverse check has three TRUE rows because B contains C300 twice and C100 once. By contrast, =A2=B2 filled through row 7 returns FALSE on all six rows: none of these row pairs line up. That row-by-row test answers a different question from membership anywhere in the other list.

In Google Sheets

Google Sheets documents COUNTIF(range, criterion). Use the same English C2 and D2 formulas for these simple text codes, then fill to row 7. Google also documents case-insensitive criteria and wildcard characters. This example compares formula results; it does not rely on Excel and Sheets having the same menus or import behavior. The formulas shown use English function names and comma separators.

Case, wildcards and input scope

COUNTIF ignores letter case in Excel and Google Sheets, so C100 and c100 match. A question mark or asterisk in the criterion acts as a wildcard. The linked function references explain using ~? or ~* to match those characters literally. The formulas above do not escape arbitrary codes automatically: this sample uses nonblank text codes without wildcard characters. For your own data, decide how to handle blanks and unwanted spaces before comparing; COUNTIF does not clean the source text for you.

Common mistakes

  • Using =A2=B2 for lists whose matching codes can appear on different rows.
  • Counting a repeat within A as a cross-list duplicate even when that code is absent from B.
  • Reading a COUNTIF count of 2 as two helper output rows; >0 still produces one Boolean flag for the source row.
  • Overwriting the original columns, or assuming this simple-code example performs case-sensitive or automatic wildcard-escaped matching.

Frequently asked questions

Why are both C200 rows FALSE?

C200 is repeated within List A, but it does not appear in List B. A repeat within one list and a value shared by two lists are different checks.

Why does C300 have a count of 2 but only one TRUE in C?

The A4 code C300 occurs twice in B2:B7. COUNTIF returns 2; the >0 comparison returns TRUE in the single helper cell C4.

Why are there two TRUE rows in C and three in D?

List A contains one C100 and one C300. List B contains one C100 and two C300 rows. Each direction flags its own source rows and preserves repeats.

Is this comparison case-sensitive?

No. COUNTIF criteria ignore letter case. Check the input-scope note for wildcard characters, blanks and spaces before using your own codes.