Excel if One Cell Equals another then Return another Cell

ou can find any other Fruit’s price by entering the Name on cell G3

MS Excel provides various options and methods to make our tasks easier. In this article, I will show some ways if we want to check cells one with another and return another cell in Excel.

5 Ways to Check If One Cell is Equal to another and Return them into another Cell

Download Practice Workbook

1. Using IF Function

IF is one of the simplest functions which is used to do a logical comparison between two values. In this method, we will see how to use the IF function to compare one cell with another and return another cell value. Before going to the example let’s know more about this function. The syntax of the function is like this:

=IF (logical_Condition, [value_if_true], [value_if_false])

In the first portion of the parameter, we need to pass our condition based on which we are going to compare. Then the second and third part defines what will be if the values after comparison get True or False.

Assuming we have a dataset of some Fruits with two columns. Every row has a specific Value. Now we will find out the rows where Fruits 1 and Fruits 2 are matched and display their values in the Matched Values column.

Comparison Using IF Function

Step 1: Enter the below formula in cell D4.

=IF(B4=C4,D4,"")

Formula Breakdown

Firstly, using the condition B4=C4 we are comparing the Fruits Name of each column Fruits 1 and Fruits 2. If the condition gets True then it will print the values from the Value column into Matched Values column.

Enter the formula with IF function

Step 2: Copy down the formula up to D8.

Copy down the formula up to D8 to get the total output

2. Using IF Function and Formula

In this method, we will use the same IF function, and depending on the condition we will use a formula and show them in another cell. Let’s think about the same dataset used in the previous method but here I will update the new Price if the Flag value is not “X” and our new price will be 2 times the current price.

Step 1: Enter the following formula in cell E4 and press Enter.

=IF(D4<>"X",C4*2,C4)

Formula Breakdown 

In this formula using D4<>” X” we are checking if the Flag value is not equal to “X” or not. If the condition is true then it will double the price otherwise it will remain the same.

Enter the formula in cell E4

Step 2: Copy down the formula up to E8.

Copy down the formula up to E8

3. Using LOOKUP Function

In terms of searching for something in Excel, the LOOKUP function will be the proper choice for that. This function allows us to search vertically or horizontally something within a condition in a certain range. For those specific purposes, there are VLOOKUP and HLOOKUP functions in Excel. Let’s see the fundamentals of the VLOOKUP function. The syntax of the function like this:

=VLOOKUP (value, table, col_index, [range_lookup])

Firstly, the value -> carries the value to look for in the first column of a table.

table -> Here will be the table name.

col_index -> It is the column index value of the table from where we will collect a value.

[range_lookup] -> This last section is for denoting the optional range.

For example, consider a dataset of some Fruits like before. But here we will have 3 columns which are Fruits, ID, Price. Now we will search Fruits price from this table using VLOOKUP.

Using VLOOKUP Function

Step 1: Enter the formula in cell G4.

=VLOOKUP(G3,B3:D8,3,0)

Formula Breakdown

Here in the function firstly I have passed the value which is G3 cell, then the table from where we want to extract data which is indicated by range B3:D8 the whole table. After that in the third part, we will get the values from the Price column which is column no 3 that’s why we need to pass 3. Lastly, 0 is used to specify that we want exactly match.

Enter the formula with Vlookup function

Step 2: You can find any other Fruit’s price by entering the Name on cell G3.

You can find any other Fruit’s price by entering the Name on cell G3

Now we will see the uses of HLOOKUP functions if our data is horizontally designed. The syntax of the HLOOKUP functions is:

=HLOOKUP (lookup_value, table_array, row_index, [range_lookup])

It is almost like the VLOOKUP function. The only difference is instead of having a column index here is the row index in the 3rd part of the parameter.

Using Hlookup function

Step 1:  Enter the formula in cell B8.

=HLOOKUP(B7,A3:F5,3,0)

Formula Breakdown

As we have discussed earlier it is almost like VLOOKUP. Here I have passed the row-wise value instead of column-wise. That’s why first have entered the row index of our desired value which is B7. Besides the table range is also change as our table is shifted horizontally.

Enter the formula using Hlookup

4. Using INDEX and MATCH Functions

In this section, we will do the same thing which was done by the LOOKUP function but the only difference is here we will not use the LOOKUP function. INDEX and MATCH functions will do the same thing as LOOKUP. Also, the dataset will be the same as well. Before going to the example let’s see the details about these two functions.

=INDEX (array, row_number, [col_number], [area_number])

This function can take a maximum of four arguments and a minimum of two arguments. In the first section of its parameter, it takes the range of cells from where we will check the index value. Then comes the row number of reference or matching value. The last two arguments are optional with them we can define or specify the column number from where the matched data will be retrieved and also the area range number.

=MATCH (lookup_value, lookup_array, [match_type])

Another mostly used function is the MATCH function. The first argument takes the lookup value or the value we are going to match. The second one is the array or range where we will search our desired data. And the last one is the match type. Depending on different match type values we can control matching.

1 -> By declaring 1 it will match or find the largest value less than or equal to the lookup value.

0 -> If we put 0 as a match type it will match the value which is exactly as the lookup value.

-1 -> This will match the smallest value greater than or equal to the lookup value.

Step 1: Enter the formula in cell G4.

=INDEX(B3:D8,MATCH(G3,B3:B8,0),3)

Formula Breakdown

MATCH(G3,B3:B8,0)

In this part, we will try to match the value which is in the G3 cell from the B3 to B8 range in our lookup table. And as we considered the exact match that’s why 0 is assigned at the last argument.

=INDEX(B3:D8,MATCH(G3,B3:B8,0),3)

The outer function is the INDEX function. In the first part, I have assigned the range of cells. Then the matched value will be calculated from the MATCH function. Lastly, 3 is used as we want to get data from the third column from our lookup table.

Enter the formula with match and index function

5. Return Items from Another Worksheet if the is a Match

Let’s have two worksheets, one is weekly meals and another is ingredients. Now I will show how to compare meals and show the ingredients in the first worksheet. The Week Meals Planning worksheet will be like this:

Meals items

And the meals ingredients worksheet will be like this:

Food ingredients

Now I will show how to find the food ingredients from the ingredient’s worksheet to the Meal worksheet by entering the name of the food in cell A12.

Step 1: Enter the formula in cell B12.

=VLOOKUP($A12,ingredients!$A3:D14,COLUMN(),FALSE)

Formula Breakdown

Firstly we have passed the lookup value cell number which is $A12, then the other worksheets (ingredients worksheet) table range $A3:D14 is sent. After the COLUMN function is passed to get the column value of that row. Lastly, FALSE is used to find an exact match, which means it is case sensitive and by declaring false it will search for the exact value matching.

Enter the formula in cell B12

Step 2: Copy the formula to the right side. Then all the ingredients of the selected Food will be displayed.

Copy the formula to the right side. Then all the ingredients of the selected Food will be displayed.

Step 3: You can check by typing any food name in cell A12 and press Enter.

Type any food name and the food ingredients

Same way if just type any food item under Food Name it will show all the ingredients of that selected item from another worksheet.

Conclusion

These are the ways to compare one cell with another and return another cell in Excel. I have shown all the methods with their respective examples. Also, I have discussed the fundamentals of this function and the most commonly used format codes of this function. If you have any other method of achieving this then please feel free to share it with us.

Md. Abdullah Al Murad

Md. Abdullah Al Murad

Hello! Welcome to my Profile. Currently, I am working and researching Microsoft Excel, and here I will be posting articles related to this. My last educational degree is BSc, and my program was Computer Science and Engineering from American International University-Bangladesh. I am a Computer Science graduate with a great interest in research and development. Always try to gather knowledge from various sources and try to make innovative solutions.

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo