Ga naar de hoofdinhoud

How to Compare Two Columns in Excel: A Step-by-Step Guide

Learn how to compare two columns in Excel for matches and for duplicates using methods like the equals operator, IF() function, EXACT(), XLOOKUP(), and more.
Bijgewerkt 27 feb 2026  · 9 min lezen

    Have you ever found yourself staring at two Excel data columns, wondering if there's a quick way to compare them? Maybe you want to identify duplicates or cross-check information. I know the feeling—it's frustrating.

    That’s why in this guide, I'll walk through step-by-step instructions to compare two columns in Excel using the most common methods, including the equals operator, the IF() function, and the EXACT() function. You’ll also learn how to use VLOOKUP() for cross-referencing and advanced techniques like conditional formatting and array formulas to make your comparisons more effective.

    TL;DR

    • Use the equals operator (=A2=B2) for a quick row-by-row match check—returns TRUE or FALSE
    • Use IF() to return custom labels like “Match” or “No Match” instead of TRUE/FALSE
    • Use EXACT() when case sensitivity matters (e.g., distinguishing “Apple” from “apple”)
    • Use Conditional Formatting to visually highlight duplicates or unique values without formulas
    • Use VLOOKUP() or XLOOKUP() (Excel 365) to cross-reference values across two lists
    • Use COUNTIF() or IF()+MATCH() to find duplicates across entire columns, not just matching rows


    Learn Excel Fundamentals

    Gain skills to use Excel effectively—no experience required.
    Start Learning For Free

    How to Compare Two Columns in Excel for Matches

    When working with data, you often need to compare two columns to identify matches. To do so, Excel offers several methods, each with advantages depending on the complexity of the data you have at hand.

    Comparing two columns using the equals operator

    One direct way to compare two columns in Excel is to use the equals = operator. The equals operator directly checks whether the values in two cells are the same. For example, I have two columns here—Column A and Column B. I also added a third column and entered the following formula to check whether both values are the same.

    =A2=B2

    Enter the Equal formula in a cell in Excel

    Enter the Equal formula in a cell. Image by Author.

    The = operator compares the content of two cells and returns TRUE if they are identical and FALSE if they are not. 

    Checking if the cells are equal or not in Excel

    Checking if two columns are equal. Image by Author.

    You can use this method when you need a quick and simple way to compare data in two different columns and verify whether their data entries match, such as when comparing lists of names or product codes.

    Comparing two columns using the IF() function

    Since the = operator only gives default TRUE or FALSE, it’s not the ideal case for every need, such as when you need to create a custom output. If you need a custom output, you can use the IF() function instead. Here is the same example except this time I use an IF() function: 

    =IF(A2=B2, "Found", "Not Found")

    IF formula in Excel

    Enter the IF() formula in the cell. Image by Author.

    I customized the output according to my preference. I wrote Found and Not Found but I could have written anything.

    Customize the message using the IF function in Excel

    Customize the message using the IF() function. Image by Author.

    Comparing two columns using the EXACT() function

    The EXACT() function compares two values by performing a case-sensitive comparison, which is helpful when you have to distinguish between uppercase and lowercase letters. For example, I have two columns, Column A and Column B, and a third column called Result, where I enter the following formula:

    =EXACT(A2,B2)

    Exact formula in Excel

    Enter the EXACT() formula in a cell. Image by Author.

    You can see I’ve written Apple and Cherry with two different cases, and when I apply the formula, it displays FALSE even though the names are the same. The reason is that it’s a case-sensitive formula, so it distinguishes between uppercase and lowercase letters.

    Compare values in Excel with the Exact function

     Compare the case-sensitive values with the Exact() function. Image by Author.

    If you want to replace the values TRUE or FALSE with your custom message, wrap your formula around the IF() function as I did below.

    =IF(EXACT(A2,B2),"Match","Mismatch")

    Combine IF with EXACT to customize the output in Excel

    To customize the message, combine IF() with EXACT(). Image by Author.

    This method is ideal when verifying usernames, product codes, or other text strings where the difference between uppercase and lowercase letters can lead to different outcomes.

    Comparing two columns using conditional formatting

    Conditional formatting is an Excel feature that allows you to apply different formatting styles to cells based on specific criteria. To highlight the duplicate values in a column, follow these steps:

    • Select the range of cells where you'd like to identify duplicate entries. 
    • Next, go to Home > Styles > Conditional Formatting > Highlight Cells Rules > Duplicate Values.

    Highlighting duplicates using advanced comparison techniques in Excel

    Selecting the duplicate values option. Image by Author

    • Once the dialog box appears, you’ll see the light red filled with dark red format preselected. Hit OK. 

    Illustration of dialog box of ‘Duplicate value’  in Excel

    Illustration of the dialog box with duplicate values. Image by Author.

    Note: If you prefer a different format, you can choose from several other pre-set formats in the dropdown menu. And if you want a completely different appearance, select Custom Format... at the bottom of the dropdown and pick your desired fill and font colors. Hit OK once you’re done. 

    Highlight the duplicate values using Conditional Formatting  in Excel

    Highlight the duplicate values using Conditional Formatting. Image by Author.

    • Similarly, select Unique from a drop-down menu to highlight the unique values instead of Duplicate.

    Highlight the unique values in Excel

    Highlight the unique values. Image by Author.

    For a deeper look at visual highlighting techniques, see our guide on how to highlight duplicates in Excel, which covers additional conditional formatting rules and Power Query approaches for large datasets.




    Comparing two columns with the VLOOKUP() function

    You can also use the VLOOKUP() function to compare columns in Excel. For example, I have the same dataset from the IF() function example, but here, I entered the following formula:

    =VLOOKUP(A2, $B$2:$B$10, 1, FALSE)

    Use <code524

    Use VLOOKUP() to compare the values. Image by Author.

    If your comparison shows errors as shown in the above image, wrap your formula inside the IFERROR() function to handle it.

    =IFERROR(VLOOKUP(A2, $B$2:$B$10, 1, FALSE), "Not Matched")

    Here's how it works:

    • It searches for the value in cell A2 within the range $B$2:$B10.

    • If an exact match is found, VLOOKUP() returns the matched value. 

    • If no match is found, IFERROR() then returns Not Matched instead of the error. 

    Handle the error using <code624

    Handle the error using IFERROR() with VLOOKUP() function. Image by Author.

    Comparing two columns using XLOOKUP() (Excel 365)

    If you’re using Excel 365 or Excel 2021, XLOOKUP() offers a more flexible alternative to VLOOKUP() for column comparisons. Unlike VLOOKUP(), it searches in any direction, doesn’t require a column index number, and handles missing values with a built-in fallback—removing the need to wrap in IFERROR().

    =XLOOKUP(A2, $B$2:$B$10, $B$2:$B$10, "Not Found")

    Here’s how the arguments work:

    • A2 — the lookup value (the item from Column A to find in Column B)
    • $B$2:$B$10 (first instance) — the lookup array (where to search)
    • $B$2:$B$10 (second instance) — the return array (what to return when found)
    • "Not Found" — the value to return when no match exists (replaces IFERROR())

    This returns the matched value from Column B when found, or “Not Found” when there’s no match. For users on Excel 2019 or earlier, use the VLOOKUP() approach described above. To understand when to choose one over the other, see our XLOOKUP vs. VLOOKUP comparison guide.

    Comparing two columns using array formulas

    Array formulas can handle multiple values at once. Instead of working on a single value, they process a range of data, making complex calculations more efficient. To use an array formula, type it in the cell and press Ctrl+Shift+Enter.

    For example, I have two columns here—Column A and Column B. Now, I want to determine if there is a match between these two.

    Two columns in Excel: Column A and Column B

    Column A and Column B contain data. Image by Author.

    For this purpose, I’ll use the following formula: 

    =SUM(--(A2=B2))

    Here:

    • The SUM() function adds up the values in the array. If there is at least one match, the sum will be greater than 0. Otherwise, it will be 0.
    • The double unary operator (-- )converts the TRUE and FALSE values to 1 and 0, resulting in an array of 1s and 0s.

    Compare columns with <code456

    Comparing columns with SUM() formulas. Image by Author.

    Now, I want to display a custom message instead of 0s and 1s, so I wrap the SUM() function inside an IF() function.

    =IF(SUM(--(A2=B2))=0, "No match", "Match")

    The IF() function checks if the sum is 0. If it is, it returns No match. Otherwise, it returns Match.

    Wrapping an Excel formula inside <code553

    SUM() formula inside IF(). Image by Author.

    And it's done. With the array formula, you can efficiently perform similar complex comparisons.

    How to Compare Two Columns in Excel for Duplicates

    You now know how to compare columns for the matches, but there are situations when you have to identify duplicates, too. To be clear, matches refer to corresponding values in different columns but in the same row. On the other hand, duplicates specifically refer to values that appear once or more across both columns but in different rows. 

    Comparing two columns using IF() and MATCH()

    The IF() function or the MATCH() function alone can’t perform lookups to identify duplicates. But if we use them together we can identify duplicates. For example, I have a dataset of month names organized in Column A and Column B. I then create another column to fetch the results. I type the following MATCH() formula in the first cell and dragged it to the last cell to check the duplicate values in my data range.

    =MATCH(A2,$B$2:$B$7,0)

    Using MATCH() function to find duplicates in excel.

    Using MATCH() to find duplicates. Image by Author.

    But you can see if the value is duplicate—MATCH() returns the position of the value from the second column. Otherwise, it throws an #N/A error. Instead of displaying a #N/A error, wrap your formula inside the ISERROR() function. This will display TRUE if there is an #N/A error. Otherwise FALSE.

    Handling errors using ISERROR() function in excel.

    Handling errors using ISERROR(). Image by Author.

    I prefer a custom output instead of TRUE or FALSE. For a custom output, wrap the formula inside an IF() function like this:

    =IF(ISERROR(MATCH(A2,$B$2:$B$7,0)),"Unique","Duplicate")

    Displaying duplicate values using IF() and MATCH() in excel.

    Displaying duplicate values using IF() and MATCH() functions. Image by Author.

    Comparing two columns using COUNTIF()

    You can also use the COUNTIF() function to compare two columns and identify duplicates. It identifies the occurrences of a value in the second column and displays 0 when the value is unique and 1 when it is a duplicate. Take a look at the following formula:

    =COUNTIF($B$2:$B$7,$A2:$A7)

    Using COUNTIF() to check the duplicate values in excel.

    Using COUNTIF() to check the duplicate values. Image by Author.

    If you want to display a custom message instead of 0s and 1, wrap the COUNTIF() inside the IF() function.

    =IF(COUNTIF($B$2:$B$7,$A2:$A7)=0,"Unique","Duplicate")

    Using IF() to display the custom messages in excel.

    Using IF() to display the custom messages. Image by Author.

    Choosing the Right Comparison Method

    With several methods available, here’s a quick reference to help you pick the right approach for your situation:

    MethodBest forCase-sensitive?Custom output?Excel version
    Equals operator (=)Quick row-by-row match checkNoNo (TRUE/FALSE only)All versions
    IF()Human-readable match/mismatch labelsNoYesAll versions
    EXACT()Case-sensitive text comparisonYesWith IF()All versions
    Conditional FormattingVisual highlighting of duplicates or unique valuesNoVisual onlyAll versions
    VLOOKUP()Cross-referencing values across two listsNoWith IFERROR()All versions
    XLOOKUP()Modern VLOOKUP replacement with built-in error handlingNoBuilt-in fallbackExcel 365 / 2021+
    Array formulasBulk match counts across entire rangesNoWith IF()All versions
    IF() + MATCH()Finding cross-column duplicates (any row)NoYesAll versions
    COUNTIF()Counting occurrences of a value in a second columnNoWith IF()All versions

    Final Thoughts

    By now, you should have a solid understanding of the different methods you can use to compare two columns in Excel, from the primary = operator to more advanced techniques like VLOOKUP(), and array formulas. Each method has its value, whether you need quick comparisons or you are performing more complex data validation tasks. The different methods also work if you need to compare two columns for matches or for duplicates.

    If you want to further sharpen your skills, I’d also encourage you to check out other resources. Start with an Introduction to Excel course to ensure a strong foundation. From there, explore the Data Analysis in Excel course to learn how to turn raw data into insightful reports.

    To boost your proficiency, consider completing the Excel Fundamentals skill track, which covers a broad range of essential functions and features. And don’t forget to grab the Excel Formulas Cheat Sheet—a handy reference guide to keep at your fingertips. 

    Advance Your Career with Excel

    Gain the skills to maximize Excel—no experience required.

    Start Today for Free

    Laiba Siddiqui's photo
    Author
    Laiba Siddiqui
    LinkedIn
    Twitter

    I'm a content strategist who loves simplifying complex topics. I’ve helped companies like Splunk, Hackernoon, and Tiiny Host create engaging and informative content for their audiences.

    Frequently Asked Excel Questions

    Can I compare columns in Excel without using formulas?

    Yes. Two built-in tools let you compare columns without writing a formula:

    • Conditional Formatting: Select both columns, go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values to visually highlight matches or unique values.
    • Go To Special: Select both columns, press Ctrl+G (or F5), click Special, then choose Row Differences. Excel will instantly select every cell in the second column that differs from the first column—no formula needed.

    For repeated use or large datasets, formulas like IF() or COUNTIF() are more reliable and easier to automate.

    How can I compare columns and highlight the first occurrence of a mismatch?

    Use Conditional Formatting with a custom formula. Select your data range (e.g., A2:B10), go to Home > Conditional Formatting > New Rule > Use a formula, and enter: =AND(A2<>B2, COUNTIF($A$2:A2, A2)=1). This highlights only the first time a mismatch appears for each value, ignoring repeated mismatches of the same entry.

    How do I compare columns for duplicates only?

    There are two approaches depending on what you need:

    • Visual highlighting: Select both columns, go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values, then click OK. Excel highlights every value that appears in both columns.
    • Formula-based: Use =IF(COUNTIF($B$2:$B$10, A2)>0, "Duplicate", "Unique") in a helper column. This checks whether each value in Column A also appears anywhere in Column B, regardless of row position.

    Can I compare columns and count the number of matches or differences?

    Yes. Use COUNTIF() to count how many times a value from one column appears in another: =COUNTIF($B$2:$B$10, A2) returns the count for a single value. To get totals across an entire range, use =SUMPRODUCT((A2:A10=B2:B10)*1) for row-by-row matches, or =SUMPRODUCT(COUNTIF(A2:A10, B2:B10)) to count how many values from Column B appear anywhere in Column A.

    Does XLOOKUP() work better than VLOOKUP() for comparing columns in Excel?

    For Excel 365 and Excel 2021 users, XLOOKUP() is generally the better choice. It searches in any direction, doesn’t require a column index number, and includes a built-in fallback value—so you don’t need to wrap it in IFERROR(). For example: =XLOOKUP(A2, $B$2:$B$10, $B$2:$B$10, "Not Found"). If you’re on Excel 2019 or earlier, VLOOKUP() is still fully supported and works well for column comparisons.

    How do I compare two columns in Excel and show only the differences?

    Use an IF() formula that returns a label only when values differ and leaves matching rows blank: =IF(A2<>B2, "Different", ""). Filter or sort that helper column to isolate the mismatches. Alternatively, use Conditional Formatting with the formula =$A2<>$B2 applied to your data range to highlight differing rows visually, without a helper column.

    Onderwerpen

    Learn Excel with DataCamp

    Leerpad

    Basisprincipes van Excel

    16 Hr
    Leer de basisvaardigheden die je nodig hebt om Excel te gebruiken, van het voorbereiden van gegevens tot het schrijven van formules en het maken van visualisaties. Je hoeft geen ervaring te hebben.
    Bekijk detailsRight Arrow
    Begin met de cursus
    Meer zienRight Arrow
    Gerelateerd

    Tutorial

    How to INDEX MATCH Multiple Criteria in Excel

    Learn step-by-step techniques to handle INDEX MATCH with multiple criteria in Excel. Include helper columns to simplify your lookups, or else apply array formulas for complex data retrieval.
    Laiba Siddiqui's photo

    Laiba Siddiqui

    Tutorial

    Index Match Excel: A Better Way to Look Up Data

    See how INDEX() and MATCH() are used to look up values within a table or range of cells Compare INDEX() and MATCH() to VLOOKUP().
    Laiba Siddiqui's photo

    Laiba Siddiqui

    Tutorial

    How to Highlight Duplicates in Excel

    Explore how you can identify duplicate entries in Excel using Conditional Formatting, the COUNTIF() formula, and Power Query. Learn best practices and troubleshoot issues.
    Laiba Siddiqui's photo

    Laiba Siddiqui

    Tutorial

    How to Merge Two Columns in Excel: Simple Formulas and More

    Merge two columns in Excel using the ampersand & operator or the CONCAT() function with a custom delimiter. Or use TEXTJOIN(), which lets you ignore blank cells.
    Laiba Siddiqui's photo

    Laiba Siddiqui

    Tutorial

    Data Wrangling with VLOOKUP in Spreadsheets

    In this tutorial, you will get an overview of how to use the VLOOKUP function and also a basic explanation of INDEX-MATCH.
    Francisco Javier Carrera Arias's photo

    Francisco Javier Carrera Arias

    Tutorial

    Data Wrangling with INDEX-MATCH in Spreadsheets

    In this tutorial, you will get an overview of how to use the INDEX-MATCH function in spreadsheets.
    Francisco Javier Carrera Arias's photo

    Francisco Javier Carrera Arias

    Meer zienMeer zien