Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Formula for Comparing Two Columns in Excel: Step-by-Step

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To compare two columns in Excel, the fastest method is to use a simple logical formula like =A2=B2 in a third column, which returns TRUE if the cells match and FALSE if they do not. For more descriptive results, use the IF function: =IF(A2=B2, "Match", "Mismatch"). This allows you to quickly identify discrepancies between two lists, such as comparing a master inventory list against a current stock count or verifying that two sets of email addresses are identical.

What You'll Need

  • Microsoft Excel installed on your computer (works across most versions including Office 365, 2021, 2019, and 2016).
  • A dataset with at least two columns of data that you wish to compare.
  • A blank third column to house the comparison formulas.

Step-by-Step

  1. Organize Your Data: Ensure the two columns you want to compare are side-by-side or clearly identified. For this guide, we will assume your first list is in Column A and your second list is in Column B, starting from row 2 (assuming row 1 contains headers).
  2. Select the Comparison Cell: Click on the first empty cell of your third column (Cell C2). This is where the result of the comparison for the first pair of data points will appear.
  3. Enter the Basic Comparison Formula: Type =A2=B2 into the cell and press Enter. Excel will evaluate whether the value in A2 is exactly equal to the value in B2. If they are identical, the cell will display "TRUE"; if they differ by even one character or space, it will display "FALSE".
  4. Apply the IF Function for Custom Labels: If you prefer words like "Match" or "Different" instead of TRUE/FALSE, delete the previous formula and type: =IF(A2=B2, "Match", "Mismatch"). Press Enter. The IF function checks the condition (A2=B2); if it is true, it returns the first value in quotes; if false, it returns the second.
  5. Drag the Fill Handle: You do not need to type the formula for every row. Hover your mouse over the bottom-right corner of cell C2 until the cursor turns into a small black cross (+). Click and drag this handle down to the bottom of your dataset. Excel will automatically adjust the row numbers (A3=B3, A4=B4, etc.) for each subsequent row.
  6. Highlight Differences with Conditional Formatting: To make mismatches stand out visually, select the range of cells in Column C. Go to the Home tab, click Conditional Formatting > Highlight Cells Rules > Text that Contains... Type "Mismatch" and choose a red fill. This allows you to scroll through thousands of rows and spot errors instantly.
  7. Verify Data Types: If the formula returns "Mismatch" but the cells look identical, check the data format. A number stored as text in Column A will not match a number stored as a value in Column B. Select both columns, go to the Home tab, and ensure the Number Format dropdown is set to "General".

Common Mistakes

One of the most frequent errors when comparing columns is ignoring trailing or leading spaces. If Cell A2 contains "Apple" and Cell B2 contains "Apple " (with a space at the end), Excel will mark this as a mismatch. These invisible characters are common when importing data from CSV files or external databases. To fix this, you can wrap your cell references in the TRIM function: =IF(TRIM(A2)=TRIM(B2), "Match", "Mismatch").

Another common mistake is case sensitivity. By default, the = operator in Excel is NOT case-sensitive. This means "APPLE" and "apple" will be treated as a match. If your data requires a strict case-sensitive comparison (such as password hashes or specific product codes), using the equals sign will lead to inaccurate results.

Users also frequently forget to lock references when comparing a single cell against an entire column. If you are comparing every cell in Column B against one specific value in cell A2, you must use an absolute reference: =B2=$A$2. Without the dollar signs, as you drag the formula down, Excel will try to compare B3 to A3, B4 to A4, and so on.

Tips

For those needing a case-sensitive comparison, use the EXACT function. The formula =EXACT(A2, B2) will return TRUE only if the text is identical in both content and capitalization. This is essential for technical data where case matters.

If you want to find if a value in Column A exists anywhere in Column B (rather than just comparing row-by-row), use the MATCH or VLOOKUP function. A common formula for this is =IF(ISNUMBER(MATCH(A2, B:B, 0)), "Found", "Not Found"). This tells you if the item in A2 exists anywhere in the entirety of Column B, regardless of which row it is on.

To speed up the process of filling formulas in very large datasets (thousands of rows), instead of clicking and dragging the fill handle, simply double-click the small black cross in the bottom-right corner of the cell. Excel will automatically shoot the formula down to the last row of the adjacent column.

When dealing with numbers, be wary of floating-point precision. Sometimes numbers that look identical in the cell actually have hidden decimal places (e.g., 10.0000001 vs 10.0000000). To avoid this, use the ROUND function to limit the comparison to a specific number of decimal places: =IF(ROUND(A2, 2)=ROUND(B2, 2), "Match", "Mismatch").

Troubleshooting

If your formula is returning "Mismatch" for cells that look exactly the same, the first step is to check for hidden characters. Use the =LEN(A2) formula in a separate cell to count the characters. If one cell has 5 characters and the other has 6, but they look the same, there is a hidden space or non-printing character present. Use the TRIM function or the Find and Replace tool (Ctrl+H) to remove extra spaces.

If the formula is returning a #VALUE! error, it usually means there is a data type conflict that Excel cannot resolve, or the formula is referencing a cell that contains an error itself. Check if either column contains #N/A or #REF! errors. You can wrap your comparison in an IFERROR function to clean this up: =IFERROR(IF(A2=B2, "Match", "Mismatch"), "Error in Data").

If the formula does not update when you change a value in Column A or B, check your Calculation Options. Go to the Formulas tab > Calculation Options and ensure "Automatic" is selected. If it is set to "Manual", Excel will not recalculate the result until you press F9.

If you are using the MATCH function to compare columns and it returns #N/A for values you know are there, ensure the third argument of the MATCH function is set to 0. The formula =MATCH(A2, B:B, 0) ensures an exact match. If you omit the 0 or use 1, Excel assumes the list is sorted and may return an approximate match or an error.

Frequently Asked Questions

Can I compare two columns on different sheets?

Yes. Instead of referencing A2, reference the sheet name: =IF(Sheet1!A2=Sheet2!A2, "Match", "Mismatch"). You can select the cells on the other sheets with your mouse while typing the formula to avoid typing errors.

How do I highlight only the unique values in two columns?

The easiest way is to select both columns, go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values. Change the dropdown from "Duplicate" to "Unique". This will highlight every cell that does not have a corresponding match in the other column.

Does the formula work for dates?

Yes, Excel treats dates as serial numbers, so =A2=B2 works perfectly for dates. However, if one cell contains a date and the other contains a date-time stamp (e.g., 2023-01-01 vs 2023-01-01 10:00 AM), they will not match. Use the INT function to compare only the date portion: =INT(A2)=INT(B2).

Can I compare three or more columns at once?

Yes, you can use the AND function. For example, =IF(AND(A2=B2, B2=C2), "All Match", "Mismatch") will only return "All Match" if all three cells are identical.

Is there a way to compare columns without using formulas?

Yes, you can use the "Remove Duplicates" tool under the Data tab, though this modifies your data. For a non-destructive method, Conditional Formatting for Duplicate Values is the best alternative to formulas.