[excel] Comparing two columns, and returning a specific adjacent cell in Excel

I am using a combination of if, vlookup, match, iserror functions, and unfortunately I've not been able to find the right formula.

Comparing two columns for matches is easy enough. the tough part has been returning a specific cell once a match is found.

So what I'm dealing with is something kind of like this:

Header     Column A   Column B   Column C  Column D
Row 1      111        AAA        112
Row 2      222        BBB        111
Row 3      333        CCC        221
Row 4      444        DDD        333

I'm trying to match column values in Column A, with Column C. So if there's match, I want the corresponding value in Column B to populate in Column D. Not a great explanation, but allow me to visually show you what I'm looking for

Header     Column A   Column B   Column C  Column D
Row 2      111        AAA        112
Row 3      222        BBB        111       AAA
Row 4      333        CCC        221
Row 5      444        DDD        333       CCC

Since Cells A1 matches cell C3, I want D to return B2

Same with Row 5. Since A4 and C5 match, I want the value for B5

Let me know if this makes sense or if you need further clarification.

This question is related to excel vlookup formulas excel-match

The answer is


Here is what needs to go in D1: =VLOOKUP(C1, $A$1:$B$4, 2, FALSE)

You should then be able to copy this down to the rest of column D.


I would advise you to swap B and C columns for the reason that I will explain. Then in D2 type: =VLOOKUP(A2, B2:C4, 2, FALSE)

Finally, copy the formula for the remaining cells.

Explanation: VLOOKUP will first find the value of A2 in the range B2 to C4 (second argument). NOTE: VLOOKUP always searches the first column in this range. This is the reason why you have to swap the two columns before doing anything.

Once the exact match is found, it will return the value in the adjacent cell (third argument).

This means that, if you put 1 as the third argument, the function will return the value in the first column of the range (which will be the same value you were looking for). If you put 2, it will return the value from the second column in the range (the value in the adjacent cell-RIGHT SIDE of the found value).

FALSE indicates that you are finding the exact match. If you put TRUE, you will be searching for the approximate match.


In cell D2 and copied down:

=IF(COUNTIF($A$2:$A$5,C2)=0,"",VLOOKUP(C2,$A$2:$B$5,2,FALSE))

Examples related to excel

Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support Converting unix time into date-time via excel How to increment a letter N times per iteration and store in an array? 'Microsoft.ACE.OLEDB.16.0' provider is not registered on the local machine. (System.Data) How to import an Excel file into SQL Server? Copy filtered data to another sheet using VBA Better way to find last used row Could pandas use column as index? Check if a value is in an array or not with Excel VBA How to sort dates from Oldest to Newest in Excel?

Examples related to vlookup

Check if an excel cell exists on another worksheet in a column - and return the contents of a different column "Unable to get the VLookup property of the WorksheetFunction Class" error Comparing two columns, and returning a specific adjacent cell in Excel VLook-Up Match first 3 characters of one column with another column Combining COUNT IF AND VLOOK UP EXCEL Excel- compare two cell from different sheet, if true copy value from other cell Vlookup referring to table data in a different sheet Excel - find cell with same value in another worksheet and enter the value to the left of it Remove #N/A in vlookup result Excel vba - convert string to number

Examples related to formulas

Comparing two columns, and returning a specific adjacent cell in Excel

Examples related to excel-match

If two cells match, return value from third Check if an excel cell exists on another worksheet in a column - and return the contents of a different column Comparing two columns, and returning a specific adjacent cell in Excel Return Max Value of range that is determined by an Index & Match lookup