Excel Formula to Compare Two Columns and Return a Value (5 examples)

Method 1 Compare Two Columns and Return a Value from the Second Column with the VLOOKUP Formula

In the following spreadsheet, we have a list of Projects and their Managers. In cell D2, the Project coordinator might input a Project name and want to see who the Manager of the Project is.

Excel formula to compare two columns and return a value

  • Use this formula in cell E2: =IFERROR(VLOOKUP(D2,project_manager,2,FALSE), “Not Assigned”)

Excel formula to compare two columns and return a value

How does this formula work?

To understand this formula, you have to know the syntax of IFERROR and VLOOKUP Excel functions.

Here’s how the formulas join together to get a result.

Excel formula to compare two columns and return a value image 3

Here’s a full review of what each part does.

Excel VLOOKUP function

Read More: How to Match Two Columns and Return a Third in Excel

Method 2 – Compare Two Columns and Return a Value (using INDEX and MATCH functions)

  • Use the following formula for cell E2: =IFERROR(INDEX(B2:B16, MATCH(D2,A2:A16,0)), “”)

Excel formula to compare two columns and return a value Image 4

If the formula doesn’t find a match, it won’t return a value since the IFERROR function’s value_if_error argument is blank.

How does the formula work?

Check out the following image.

Excel formula to compare two columns and return a value Image 5

Here’s how the formula works in steps:

  • The MATCH function returns the relative position of lookup_value D2. Say, the value is DD. It will return 4 as DD is in 4th position in the lookup_array $A$2:$A$16. If no matching was found, the MATCH function would return an error value.
  • The INDEX function searches for the 4th value in the array $B$2:$B$16. And it finds value, John. So, for this example, the INDEX function will return the value, John.
  • The IFERROR function finds a valid value for its value So, it will return the value. If it would find an error value, then it would return a blank.

Read More: How to Count Matches in Two Columns in Excel (5 Easy Ways)

Method 3 – Two Columns Lookup

Here’s a dataset of employees and their salaries. We’ll find a salary for an employee with a given first and last name.

You cannot perform two columns lookup with regular Excel formulas. You have to use an Array formula.

  • Input this formula in cell F4: {=INDEX(C2:C11,MATCH(F2&F3, A2:A11&B2:B11,0))}

Excel formula to compare two columns and return a value Image 6

  • Press Ctrl + Shift + Enter on your keyboard. You will get the formula as an array formula.

Excel formula to compare two columns and return a value Image 7

How does this array formula work?

At first, let’s understand the Match function part.

You can imagine this array formula as a series of the following formulas:

  • MATCH(F2&F3, A2&B2,0)
  • MATCH(F2&F3, A3&B3,0)
  • MATCH(F2&F3, A4&B4,0)
  • … … …
  • … … …
  • MATCH(F2&F3, A11&B11,0)

This series will be stored in Excel memory as <code>MATCH (JamesSmith, {“MarissaMayer”; “MarissaAhmed”; “MarissaKawser”; “ArissaAhmed”; “ArissaKawser”; “JamesClark”; “JamesSmith”; “JohnWalker”; “JohnReed”; “JohnLopez”}, 0)

From the above MATCH function, what will be returned? MATCH function will return 7 as JamesSmith is found at position 7 of the array.

The rest is simple. In the array of C2:C11, the 7th position is value 210745. So, the overall function returns 210745 in cell F4.

Read More: How to Compare Text Between Two Cells in Excel (10 Methods)


Similar Readings


Method 4 – Compare Two columns and List Differences in the Third Column

Here are two lists that we need to compare and show the values of List 2 under a new column but without the values that are also in List 1.

  • Use this formula in cell C2: =IF(ISNA(MATCH(B2, $A$2:$A$8,0)),B2, “”)
  • Drag the formula down to copy it for the other cells.
  • We get the following results for the sample.

Excel formula to compare two columns and return a value Image 8

How does this formula work?

Excel formula to compare two columns and return a value Image 9

Let’s break down the formula into pieces:

  • The Match function will search for cell value B2 in the range $A$2:$A$8. If it finds a match, it will return the position of the value, otherwise, it will return the #N/A. Value 600 of cell B2 is not found anywhere on the list. So, the Match function will return the #N/A error.
  • The ISNA function returns TRUE if it finds the #N/A error, otherwise, it will return a FALSE In this case, ISNA will return TRUE value as Match function returns #N/A error.
  • When the ISNA function returns a TRUE value, IF function’s value_if_true argument will be returned and it is B2, the value of B2 is 600. So, this formula will return 600 as a value.

Read More: How to Compare Two Lists and Return Differences in Excel

Method 5 – Compare Two Columns Row by Row

You might also want to compare two columns row by row like the following image.

Excel formula to compare two columns and return a value Image 10

  • Use the following formula in cell C2: =IF(A2=B2, “Matched”, “Not Matched”)
  • AutoFill to the other cells in the result column.

This is a straightforward Excel IF function. If the cells A2 and B2 are the same, “Matched” value will show in cell C2 and if the cells A2 and B2 are not the same, then the “Not Matched” value will show as the output.

This comparison is case-insensitive. “Milk” and “milk” are treated as the same in this comparison.

  • We can also use the EXACT function to find the exactly matched values. Change the formula to the following: =IF(EXACT(A2,B2), "Matched", "Not Matched")

Excel formula to compare two columns and return a value Image 11

You see now “Milk” and “milk” are treated differently. They are not the same.

Read More: How to Compare Text in Two Columns in Excel

Download the Working File


Further Readings

Get FREE Advanced Excel Exercises with Solutions!
Kawser Ahmed
Kawser Ahmed

Kawser Ahmed is a Microsoft Excel Expert, Udemy Course Instructor, Data Analyst, Finance professional, and Chief Editor of ExcelDemy. He is the founder and CEO of SOFTEKO (a software and content marketing company). He has a B.Sc in Electrical and Electronics Engineering. As a Udemy instructor, he offers 8 acclaimed Excel courses, one selected for Udemy Business. A devoted MS Excel enthusiast, Kawser has contributed over 200 articles and reviewed thousands more. His expertise extends to Data Analysis,... Read Full Bio

10 Comments
  1. Thank you very much. First of all, sorry for my bad english, than i want to congrats you for this lection and you have made in me one of the fan of your blog.

  2. Very clearly explained. This was a great help!

  3. Thanks a lot, I liked your lesson, and liked your way of explaining (how does this formula work?) I like it so much. Thanks again.

  4. Thank you for this comprehensive and useful tutorial 🙂

  5. Thank you! Thank you! Thank you! Your formula: “3) Two Columns Lookup” solved a very complex problem for me. It also has automated a process that has been taking me quite a long time to do manually! Your examples made it very clear as to what I needed to do!

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo