How to Compare Two Columns in Excel (for matches & differences)

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

Last updated

The one query that I get a lot is – ‘how to compare two columns in Excel?’.

This can be done in many different ways, and the method to use will depend on the data structure and what the user wants from it.

For example, you may want to compare two columns and find or highlight all the matching data points (that are in both the columns).

Or you may want only the differences (where a data point is in one column and not in the other), etc.

Since I get asked about this so much, I decided to write this massive tutorial with an intent to cover most (if not all) possible scenarios.

In this tutorial, I’ll show you how to compare two columns row by row, highlight matches and differences, find missing values, and pull matching data.

If you find this useful, do pass it on to other Excel users.

Follow along with the example file

Compare Two Columns in Excel.xlsx

Download

Note that the techniques to compare columns shown in this tutorial are not the only ones.

Based on your dataset, you may need to change or adjust the method. However, the basic principles would remain the same.

If you think there is something that can be added to this tutorial, let me know in the comments section.

Compare Two Columns For Exact Row Match

This one is the simplest form of comparison. In this case, you need to do a row by row comparison and identify which rows have the same data and which ones do not.

Below is a data set where I need to check whether the name in column A (Name in CRM) is the same in column B (Name on Invoice) or not.

Names in the CRM in column A and the names on the invoice in column B, with an empty Same Name? column

If there is a match, I need the result as “TRUE”, and if it doesn’t match, then I need the result as “FALSE”.

The below formula would do this:

=A2:A11=B2:B11
The formula =A2:A11=B2:B11 in cell C2 returning TRUE for matching names and FALSE for Intel and Samsung

Enter this formula in cell C2, and it spills down automatically for all the rows.

It compares each name in column A with the name in the same row in column B. Intel and Samsung return FALSE because the invoice says “Intel Corp” and “Samsng”.

Spilling formulas like this one work in Microsoft 365 and Excel 2021 or later. In older versions, use =A2=B2 in cell C2 and copy it down.

If you want to get a more descriptive result, you can use a simple IF formula to return “Match” when the names are the same and “Mismatch” when the names are different.

=IF(A2:A11=B2:B11,"Match","Mismatch")
The IF formula in cell D2 returning Match or Mismatch for each row

Enter this formula in cell D2. In older versions of Excel, use =IF(A2=B2,"Match","Mismatch") and copy it down.

Note that both these formulas are not case sensitive. So ‘IBM’ in column A and ‘ibm’ in column B are treated as a match.

In case you want to make the comparison case sensitive, use the following IF formula:

=IF(EXACT(A2:A11,B2:B11),"Match","Mismatch")
The case-sensitive IF and EXACT formula in cell E2 showing Mismatch for IBM and ibm

With the above formula, ‘IBM’ and ‘ibm’ would be considered two different names and the above formula would return ‘Mismatch’.

Enter this formula in cell E2. In older versions of Excel, use =IF(EXACT(A2,B2),"Match","Mismatch") and copy it down.

The EXACT function checks whether two text values are exactly the same, including the case of every letter.

If you need more ways to compare text in Excel, I have a separate tutorial on that.

Highlight Row Differences Using Go To Special (Ctrl + \)

If all you want is to quickly spot the rows where the two columns are different, you don’t need a formula at all.

Excel has a built-in Row Differences option that selects every cell that doesn’t match the other column in its row. You can then give those cells a fill color.

Below I have the same dataset with names in column A (Name in CRM) and column B (Name on Invoice).

Names in the CRM and on the invoice in columns A and B

Here are the steps to highlight the row differences:

  1. Select the names in both columns (A2:B11 in this example). Start the selection from cell A2, so column A is the column Excel compares against.
The names in A2:B11 selected, starting from cell A2
  1. Press Ctrl + \ (the backslash key). This selects the cells in column B that are different from column A in the same row.
Cells B5 and B8 selected because Intel Corp and Samsng do not match the names in column A
  1. Click the Home tab, click the Fill Color drop-down, and pick a color.
The Fill Color drop-down on the Home tab with the orange color highlighted

This highlights ‘Intel Corp’ and ‘Samsng’, the two names that don’t match the name in column A.

The mismatched names Intel Corp and Samsng highlighted in orange in column B

If the shortcut doesn’t work on your keyboard, go to Home > Find & Select > Go To Special, select Row differences, and click OK. It does the same thing.

Like the equal to operator, Row Differences is not case sensitive, so it doesn’t flag ‘IBM’ and ‘ibm’.

Also note that this is a one-time highlight, so it won’t update if you change the data later.

Highlight Rows with Matching Data (or Different Data)

If you want to highlight the rows that have matching data (instead of getting the result in a separate column), you can do that by using Conditional Formatting.

Unlike the Row Differences method, conditional formatting stays live. If you change a name, the highlight updates on its own.

Below I have the dataset with names in column A (Name in CRM) and column B (Name on Invoice), and I want to highlight the rows where both names are the same.

Names in the CRM and on the invoice in columns A and B

Here are the steps to do this:

  1. Select the entire dataset (without the headers). In this example, that’s A2:B11.
The data in A2:B11 selected without the header row
  1. Click the ‘Home’ tab.
The Home tab in the Excel ribbon
  1. In the Styles group, click on the ‘Conditional Formatting’ option.
The Conditional Formatting option in the Styles group of the Home tab
  1. From the drop-down, click on ‘New Rule’.
The Conditional Formatting drop-down with the New Rule option
  1. In the ‘New Formatting Rule’ dialog box, click on the ‘Use a formula to determine which cells to format’.
The New Formatting Rule dialog box with Use a formula to determine which cells to format selected
  1. In the formula field, enter the formula: =$A2=$B2
The formula =$A2=$B2 entered in the New Formatting Rule dialog box
  1. Click the Format button and specify the format you want to apply to the matching cells.
The Fill tab of the Format Cells dialog box with a light green color picked
  1. Click OK.

This will highlight all the cells where the names are the same in each row.

The eight rows where the name in column A matches column B highlighted in green

The dollar sign in $A2 and $B2 locks the columns but not the row. So every cell in row 2 checks A2 against B2, every cell in row 3 checks A3 against B3, and so on.

Make sure the row number in the formula (2 here) is the first row of your selection. If you select from row 1, use =$A1=$B1 instead.

If you want to highlight the rows where the names are different, follow the same steps, but use this formula in step 6:

=$A2<>$B2
Only the Intel and Samsung rows highlighted because their names are different

The <> operator means ‘not equal to’, so only the rows for Intel and Samsung get highlighted.

Compare Two Columns and Highlight Matches

If you want to compare two columns and highlight matching data, you can use the duplicate functionality in conditional formatting.

Note that this is different than what we have seen when comparing each row. In this case, we will not be doing a row by row comparison.

Often, you’ll get datasets where there are matches, but these may not be in the same row.

Something as shown below, where I have last year’s clients in column A and this year’s clients in column B:

Last year's clients in column A and this year's clients in column B, with matches in different rows

Note that the list in column A is bigger than the one in B. Also some names are there in both the lists, but not in the same row (such as IBM, Adobe, Walmart).

If you want to highlight all the matching company names, you can do that using conditional formatting.

Here are the steps to do this:

  1. Select the entire data set (A2:B14 in this example).
Both client lists selected in A2:B14
  1. Click the Home tab, and in the Styles group, click on the ‘Conditional Formatting’ option.
The Conditional Formatting drop-down open on the Home tab
  1. Hover the cursor on the Highlight Cells Rules option, and click on Duplicate Values.
Highlight Cells Rules in the Conditional Formatting menu with the Duplicate Values option
  1. In the Duplicate Values dialog box, make sure ‘Duplicate’ is selected.
The Duplicate Values dialog box with Duplicate selected
  1. Specify the formatting. I’ve picked ‘Green Fill with Dark Green Text’.
The Duplicate Values dialog box with Green Fill with Dark Green Text selected
  1. Click OK.

The above steps would give you the result as shown below.

The six clients that appear in both lists highlighted in green, in different rows

All six names that appear in both lists get highlighted, no matter which row they are in. Excel ignores the empty cells at the bottom of column B.

Note: Conditional Formatting duplicate rule is not case sensitive. So ‘Apple’ and ‘apple’ are considered the same and would be highlighted as duplicates.

Important: This rule also highlights a name that appears twice in the same list, even when it’s not in the other list.

If your lists can have repeats like that, use a formula rule instead. Select A2:A14 and create a ‘Use a formula’ rule (same as the previous section) with this formula:

=ISNUMBER(MATCH(A2,$B$2:$B$10,0))

This highlights a name in column A only when it’s found in column B.

And if you only want to find duplicates within one list, I have a separate tutorial on that.

Compare Two Columns and Highlight Differences

In case you want to highlight the names which are present in one list and not the other, you can use the conditional formatting for this too.

Below I have the same two lists, with last year’s clients in column A and this year’s clients in column B.

Last year's clients in column A and this year's clients in column B

Here are the steps to highlight the differences:

  1. Select the entire data set (A2:B14).
Both client lists selected in A2:B14
  1. Click the Home tab, and in the Styles group, click on the ‘Conditional Formatting’ option.
The Conditional Formatting drop-down open on the Home tab
  1. Hover the cursor on the Highlight Cells Rules option, and click on Duplicate Values.
Highlight Cells Rules in the Conditional Formatting menu with the Duplicate Values option
  1. In the Duplicate Values dialog box, make sure ‘Unique’ is selected.
The Duplicate Values dialog box with Unique selected
  1. Specify the formatting. I’ve kept the default ‘Light Red Fill with Dark Red Text’.
The Duplicate Values dialog box with Unique and Light Red Fill with Dark Red Text selected
  1. Click OK.

This will give you the result as shown below. It highlights all the cells that have a name that is not present on the other list.

Names that are only in one of the two lists highlighted in red

So you get the seven clients from last year that are missing this year, and also the three new clients this year (Toyota, Shopify, and Zoom).

Compare Two Columns and Find Missing Data Points

If you want to identify whether a data point from one list is present in the other list, you need to use the lookup formulas.

Suppose you have a dataset as shown below and you want to identify companies that are present in column A but not in column B.

Last year's and this year's client lists with an empty Missing This Year? column

Below is the formula that will do this:

=ISNA(XMATCH(A2:A14,B2:B10))
The ISNA and XMATCH formula in cell C2 returning TRUE for clients missing from this year's list

Enter this formula in cell C2, and it spills down for all 13 names in column A.

It returns TRUE for the companies that are missing in column B, and FALSE for the ones that are there.

How this formula works:

  • XMATCH(A2:A14,B2:B10) looks for each company name from column A in column B. If it finds it, it returns its position in column B, else it returns a #N/A error.
  • ISNA(…) returns TRUE when the result is the #N/A error and FALSE when it isn’t. So the names which return TRUE are the ones that are missing in column B.

XMATCH works in Microsoft 365 and Excel 2021 or later. In older versions, use this formula in cell C2 and copy it down:

=ISNA(MATCH(A2,$B$2:$B$10,0))

If you’re more used to VLOOKUP, =ISERROR(VLOOKUP(A2,$B$2:$B$10,1,0)) gives you the same TRUE/FALSE result.

This formula uses VLOOKUP to check whether a company name in A is present in column B or not.

If it is present, it will return that name from column B, else it will return a #N/A error.

ISERROR then returns TRUE when the VLOOKUP result is an error, and FALSE when it isn’t.

Note: Personally, I prefer using the Match function (or the combination of INDEX/MATCH) instead of VLOOKUP.

I find it more flexible and powerful. You can read the difference between Vlookup and Index/Match here.

If you want to get a list of all the names where there is no match, you can filter the result column to get all cells with TRUE.

Or you can get that list with a formula, which is what I cover next.

Get a List of Missing or Matching Values Using FILTER

The previous formula tells you which names are missing, but you still have to filter for them.

With the FILTER function, you can pull the list of missing names (or matching names) into a separate column with one formula.

Below I have the same two lists, and I want a list of last year’s clients that are not in this year’s list.

Last year's clients in column A and this year's clients in column B

Here is the formula that will give us the result:

=FILTER(A2:A14,ISNA(XMATCH(A2:A14,B2:B10)))
The FILTER formula in cell D2 listing the seven clients missing from this year's list

Enter it in cell D2, and it spills the seven missing names (Netflix, Pfizer, Boeing, Intel, FedEx, Spotify, and Uber).

The ISNA(XMATCH(…)) part is the same check from the previous section, and it returns TRUE for every missing name.

FILTER then keeps only the names from column A where that check is TRUE.

If you want the names that are in both lists instead, swap ISNA for ISNUMBER:

=FILTER(A2:A14,ISNUMBER(XMATCH(A2:A14,B2:B10)))
The FILTER formula in cell D2 listing the six clients that are in both lists

This returns the six clients that appear in both lists: IBM, Starbucks, Adobe, Walmart, Nike, and Oracle.

If there’s a chance that nothing matches, add a third argument such as “None found” to FILTER. Otherwise, the formula returns a #CALC! error when there’s nothing to show.

FILTER and XMATCH work in Microsoft 365 and Excel 2021 or later.

Compare Two Columns and Pull the Matching Data

If you have two datasets and you want to compare items in one list to the other and fetch the matching data point, you need to use the lookup formulas.

For example, in the below dataset, I have company names and their market values in columns A and B (these are sample values, not live numbers).

Company names with sample market values, and a list of companies in column D to look up

I want to fetch the market value for each company in column D. To do this, I need to look up that name in column A and then fetch the corresponding market value from column B.

Below is the formula that will do this:

=XLOOKUP(D2:D7,A2:A14,B2:B14,"Not found")
The XLOOKUP formula in cell E2 returning each market value and Not found for Tesla

Enter this formula in cell E2, and it spills the market value for all six companies in column D.

The XLOOKUP function looks for each name from D2:D7 in A2:A14 and returns the value from the same row in B2:B14.

Tesla isn’t in the table, so XLOOKUP returns “Not found” (the fourth argument) instead of a #N/A error.

XLOOKUP works in Microsoft 365 and Excel 2021 or later. If you’re using an older version, use either of these formulas in cell E2 and copy it down:

=VLOOKUP(D2,$A$2:$B$14,2,0)
=INDEX($A$2:$B$14,MATCH(D2,$A$2:$A$14,0),2)

Both return a #N/A error for Tesla, since it isn’t in the table. Here is my guide on the VLOOKUP formula if you want to learn more about it.

If you’re not sure which one to use, here’s how VLOOKUP and XLOOKUP compare.

Pull the Matching Data Using a Partial Match (Wildcards)

In case you get a dataset where there is a minor difference in the names in the two columns, using the above-shown lookup formulas is not going to work.

These lookup formulas need an exact match to give the right result. There is an approximate match option in VLOOKUP or MATCH function, but that can’t be used here.

Suppose you have the data set as shown below.

Note that there are names that are not complete in column D (such as JPMorgan instead of JPMorgan Chase and Exxon instead of ExxonMobil).

Company table with full names and a list of partial names such as JPMorgan and Exxon in column D

In such a case, you can use a partial lookup by using wildcard characters.

The following formula will give us the right result in this case:

=XLOOKUP("*"&D2:D7&"*",A2:A14,B2:B14,"Not found",2)
The XLOOKUP wildcard formula in cell E2 returning the market value for each partial name

Enter it in cell E2, and it spills the market value for all six partial names.

In the above example, the asterisk (*) is a wildcard character that can represent any number of characters.

When the lookup value is flanked with it on both sides, any value in column A which contains the lookup value in column D would be considered as a match.

For example, Exxon would be a match for ExxonMobil (as * can represent any number of characters).

The 2 at the end is important. It tells XLOOKUP to treat the asterisk as a wildcard. Without it, XLOOKUP looks for the literal text Exxon and returns “Not found”.

In older versions of Excel, use either of these formulas in cell E2 and copy it down:

=VLOOKUP("*"&D2&"*",$A$2:$B$14,2,0)
=INDEX($A$2:$B$14,MATCH("*"&D2&"*",$A$2:$A$14,0),2)

VLOOKUP and MATCH accept wildcards in exact match mode by default, so they don’t need that extra argument.

Also, keep in mind that a partial match returns the first value that contains your text. So keep the partial names specific enough that they can only match one company.

So these are some of the ways you can compare two columns in Excel.

I hope you found this tutorial useful!

You May Also Like the Following Excel Tips & Tutorials:

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

59 thoughts on “How to Compare Two Columns in Excel (for matches & differences)”

  1. Need help. Here is my problem.
    ID Rate ID Months Rate
    R000034567 00 51287 R000034567 12
    R000034565 00 4587 R000034565 6
    R000034562 00 6528 R000034562 8

    Trying to fill the rates to the last column based on the ID. What would the formula be to compare the two ID column.

    Reply
  2. Hi, I have another question about “Compare Two Columns and Highlight Mismatched Data”. This helps to identify unique values in 2 columns A and B , but it fails if suppose there are 2 similar values in Column A and that value doesn’t exits in Column B, it should highlight it because it is a mismatch in Column A and Column B but it doesn’t do that. It should not check for duplicates within same column as that is not my goal. I want to strictly compare Column A and Column B

    Reply
  3. I have a question , I have set of values (separated by new line in notepad), and I want to highlight those column which matches those set of values.
    Suppose I have in my notepad each in new line following value – ABC, XYZ, MTX, LAB etc.
    And I have a column which has 200 entries with some of the entries contains above values. How do I highlight those columns?

    Reply
  4. The example where you highlight matches in both columns where the values are in different positions using the duplicates option unfortunately also highlights duplicates within the same column and does not need to exist at all in the other column.

    Reply
  5. Hi Sir, is it possible to assist me on how to get the top importer who has the most entries/transactions for a certain period? Can I send the sample file to you? Thanks

    Reply
  6. Is there a way to compare data with a “contains similar” type of lens? I want to be able to find names like, “Harry & Son” and “Harry and Son” and “Harry and Son LTD.” ETC.

    Reply
  7. excellent summary, not too much not too little , with excellent visuals, mission accomplished thanks

    Reply
  8. I cannot get any of the above to work accurately when looking for matches in every row across two columns when using dates – I can see matching dates but the formula gives a negative instead of a positive match. Any help to resolve?

    Reply
  9. Hi there – I’ve been looking but I don’t think I have yet found a tutorial for my use-case. I wonder if you have one or can answer my question. I have two sets of two columns of non-matching data (1st set has a set of names and values across date period 1, 2nd set has a set of names and values across date period 2) but whilst some of the names repeat in both data sets there are also names that are unique to set 1 and set 2. I wish to put those names (and their corresponding values) that are common to both data sets on the same row and then, beneath these common names, list those that are unique to each list. Is there a route to this?

    Reply
  10. I have some values in first column and some values in second column I want all the values that are duplicate in first column and second column in other column in other sheet

    Reply
  11. I have 3 columns. One is on the first tab and the other 2 are on the second tab. I want the column on the first tab to find any matching values in the column in the second tab. If there is a match/multiple matches, I want it to grab the values in the 3 column on the second tab and return the sum. Hope this makes sense and there is someone that can assist!

    Reply
  12. You are absolutely the hero of the day. Your tutorial shows me the way to cross reference thousands of data points and pull over the missing data I needed, in just a matter of minutes. THANK YOU!

    Reply
  13. This is a great article, thanks a lot.
    Many people don’t know that one can use SQL statements to access Excel spreadsheets. I wrote a tool called SelectCompare that facilitates comparison of data sets, among others Excel spreadsheets. There is quite a bit of documentation on the website how to set up data connection and write SELECT statements.

    Reply
  14. I have 2 lists:
    1) One has names with scores. The names are in alphabetical order.

    2)The other has the same names. No scores and the names are in groups. Not in the alphabetical order.

    Is there away I can combine the two lists so the score appears next to the name; without affecting the groups?

    Reply
  15. I’ve tried each of your formulas. None work, so I have to be doing something wrong — this can’t be a unique problem.

    I have 433 names in Column A, and 298 in Column B. All the names in Column B are also in A, and I formatted all of them to be identical spellings, all surnames. So what I want are the 135 names in Column A that are not in Column B to appear in Column C.

    If Excel can’t do that (which would astonish me), even just highlighting either all the duplicates (that is, names in BOTH columns), and NOT the unique names in Column A, would help.

    The best I can get instead is duplicates WITHIN a column — that is, it will highlight “Bishop Bishop” (two different people with the same name) in each column. But not matter what I do, I can’t get Excel to highlight “Adams” because it is in both columns, nor “Abraham” because it is only in Column A.

    Help?

    Reply
    • You can use vlookup or index/match to look for those names in B which also appear in A, then it will return #N/A for those names that are not found. And you can sort/filter as applicable.

      Reply
  16. Good Job. it is very useful to save our time. if your can help me on the following also appreciated.
    I want to find same value in two column as debit and credit. how to select those value in excel formula( this is just reconciling debit credit entries updated in Excel)

    Reply
  17. Thank you!! This gave me exactly what I wanted to know after searching other places for ten minutes.

    Reply
  18. I need help comparing two columns for duplicates and unique values. I know I can do this using conditional formatting however my issue is that for example in column 1 I have duplicates so when I apply the conditional formatting it is picking the duplicates up in the same column however I only want to pick up the duplicates against the two columns. E.g.

    Column 1 could have:
    Red
    Yellow
    Red
    Green

    Column 2 could have:
    Yellow
    Blue
    Purple
    Green

    When I apply the conditional formatting it picks up Red as a duplicate as it appears twice in column one but only want to find duplicates comparing the two columns so I would like it to pick up: Yellow and Green.

    How can I achieve this?

    Reply
    • Hi Tricia, I have the same problem as you.If by now you do know how to solve it please let me know. Thanks a ton!

      Reply
  19. I need help on how to compare everyday Item that we’re sold. Then I need to put the comparison price list. How do I check if Price was already there so I do not have to do it again?

    Reply
  20. thanks a lot for your support which has given me great support in my work and please share the formulas to pullout the duplicates separate from the data.

    Reply
      • very useful, thank you Sumit. If you can assist on another similar case. I need to use conditional formation where, if I want to compare two numbers and use colour to identify the difference, be it positive or negative. For an example: If value is cell A is lower than a value in cell B, then highlight be in Red, otherwise highlight cell B in green. I need to use this to highlight variances in sales targets vs actual sales on different product lines.

        Reply

Leave a Comment

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.