If and compare excel

Содержание

  1. IF function
  2. Simple IF examples
  3. Common problems
  4. Need more help?
  5. IF function
  6. Simple IF examples
  7. Common problems
  8. Need more help?
  9. Using IF with AND, OR and NOT functions
  10. Examples
  11. Using AND, OR and NOT with Conditional Formatting
  12. Need more help?
  13. See also
  14. Function IF in Excel with a few examples of conditions
  15. The syntax of the function «IF» with one condition
  16. The function IF in Excel with multiple conditions
  17. Enhanced functionality with the help of the operators «AND» and «OR»
  18. How to compare data in two tables

IF function

The IF function is one of the most popular functions in Excel, and it allows you to make logical comparisons between a value and what you expect.

So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.

For example, =IF(C2=”Yes”,1,2) says IF(C2 = Yes, then return a 1, otherwise return a 2).

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it’s false.

IF(logical_test, value_if_true, [value_if_false])

The condition you want to test.

The value that you want returned if the result of logical_test is TRUE.

The value that you want returned if the result of logical_test is FALSE.

Simple IF examples

In the above example, cell D2 says: IF(C2 = Yes, then return a 1, otherwise return a 2)

In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values. It can also be used to evaluate errors. You are not limited to only checking if one thing is equal to another and returning a single result, you can also use mathematical operators and perform additional calculations depending on your criteria. You can also nest multiple IF functions together in order to perform multiple comparisons.

B2,”Over Budget”,”Within Budget”)» loading=»lazy»>

=IF(C2>B2,”Over Budget”,”Within Budget”)

In the above example, the IF function in D2 is saying IF(C2 Is Greater Than B2, then return “Over Budget”, otherwise return “Within Budget”)

B2,C2-B2,»»)» loading=»lazy»>

In the above illustration, instead of returning a text result, we are going to return a mathematical calculation. So the formula in E2 is saying IF(Actual is Greater than Budgeted, then Subtract the Budgeted amount from the Actual amount, otherwise return nothing).

In this example, the formula in F7 is saying IF(E7 = “Yes”, then calculate the Total Amount in F5 * 8.25%, otherwise no Sales Tax is due so return 0)

Note: If you are going to use text in formulas, you need to wrap the text in quotes (e.g. “Text”). The only exception to that is using TRUE or FALSE, which Excel automatically understands.

Common problems

What went wrong

There was no argument for either value_if_true or value_if_False arguments. To see the right value returned, add argument text to the two arguments, or add TRUE or FALSE to the argument.

This usually means that the formula is misspelled.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Источник

IF function

The IF function is one of the most popular functions in Excel, and it allows you to make logical comparisons between a value and what you expect.

So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.

For example, =IF(C2=”Yes”,1,2) says IF(C2 = Yes, then return a 1, otherwise return a 2).

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it’s false.

IF(logical_test, value_if_true, [value_if_false])

The condition you want to test.

The value that you want returned if the result of logical_test is TRUE.

The value that you want returned if the result of logical_test is FALSE.

Simple IF examples

In the above example, cell D2 says: IF(C2 = Yes, then return a 1, otherwise return a 2)

In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values. It can also be used to evaluate errors. You are not limited to only checking if one thing is equal to another and returning a single result, you can also use mathematical operators and perform additional calculations depending on your criteria. You can also nest multiple IF functions together in order to perform multiple comparisons.

B2,”Over Budget”,”Within Budget”)» loading=»lazy»>

=IF(C2>B2,”Over Budget”,”Within Budget”)

In the above example, the IF function in D2 is saying IF(C2 Is Greater Than B2, then return “Over Budget”, otherwise return “Within Budget”)

B2,C2-B2,»»)» loading=»lazy»>

In the above illustration, instead of returning a text result, we are going to return a mathematical calculation. So the formula in E2 is saying IF(Actual is Greater than Budgeted, then Subtract the Budgeted amount from the Actual amount, otherwise return nothing).

In this example, the formula in F7 is saying IF(E7 = “Yes”, then calculate the Total Amount in F5 * 8.25%, otherwise no Sales Tax is due so return 0)

Note: If you are going to use text in formulas, you need to wrap the text in quotes (e.g. “Text”). The only exception to that is using TRUE or FALSE, which Excel automatically understands.

Common problems

What went wrong

There was no argument for either value_if_true or value_if_False arguments. To see the right value returned, add argument text to the two arguments, or add TRUE or FALSE to the argument.

This usually means that the formula is misspelled.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Источник

Using IF with AND, OR and NOT functions

The IF function allows you to make a logical comparison between a value and what you expect by testing for a condition and returning a result if that condition is True or False.

=IF(Something is True, then do something, otherwise do something else)

But what if you need to test multiple conditions, where let’s say all conditions need to be True or False ( AND), or only one condition needs to be True or False ( OR), or if you want to check if a condition does NOT meet your criteria? All 3 functions can be used on their own, but it’s much more common to see them paired with IF functions.

Use the IF function along with AND, OR and NOT to perform multiple evaluations if conditions are True or False.

IF(AND()) — IF(AND(logical1, [logical2], . ), value_if_true, [value_if_false]))

IF(OR()) — IF(OR(logical1, [logical2], . ), value_if_true, [value_if_false]))

IF(NOT()) — IF(NOT(logical1), value_if_true, [value_if_false]))

The condition you want to test.

The value that you want returned if the result of logical_test is TRUE.

The value that you want returned if the result of logical_test is FALSE.

Here are overviews of how to structure AND, OR and NOT functions individually. When you combine each one of them with an IF statement, they read like this:

AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False)

OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False)

NOT – =IF(NOT(Something is True), Value if True, Value if False)

Examples

Following are examples of some common nested IF(AND()), IF(OR()) and IF(NOT()) statements. The AND and OR functions can support up to 255 individual conditions, but it’s not good practice to use more than a few because complex, nested formulas can get very difficult to build, test and maintain. The NOT function only takes one condition.

Here are the formulas spelled out according to their logic:

=IF(AND(A2>0,B2 0,B4 50),TRUE,FALSE)

IF A6 (25) is NOT greater than 50, then return TRUE, otherwise return FALSE. In this case 25 is not greater than 50, so the formula returns TRUE.

IF A7 (“Blue”) is NOT equal to “Red”, then return TRUE, otherwise return FALSE.

Note that all of the examples have a closing parenthesis after their respective conditions are entered. The remaining True/False arguments are then left as part of the outer IF statement. You can also substitute Text or Numeric values for the TRUE/FALSE values to be returned in the examples.

Here are some examples of using AND, OR and NOT to evaluate dates.

Here are the formulas spelled out according to their logic:

IF A2 is greater than B2, return TRUE, otherwise return FALSE. 03/12/14 is greater than 01/01/14, so the formula returns TRUE.

=IF(AND(A3>B2,A3 B2,A4 B2),TRUE,FALSE)

IF A5 is not greater than B2, then return TRUE, otherwise return FALSE. In this case, A5 is greater than B2, so the formula returns FALSE.

Using AND, OR and NOT with Conditional Formatting

You can also use AND, OR and NOT to set Conditional Formatting criteria with the formula option. When you do this you can omit the IF function and use AND, OR and NOT on their own.

From the Home tab, click Conditional Formatting > New Rule. Next, select the “ Use a formula to determine which cells to format” option, enter your formula and apply the format of your choice.

Edit Rule dialog showing the Formula method» loading=»lazy»>

Using the earlier Dates example, here is what the formulas would be.

If A2 is greater than B2, format the cell, otherwise do nothing.

=AND(A3>B2,A3 B2,A4 B2)

If A5 is NOT greater than B2, format the cell, otherwise do nothing. In this case A5 is greater than B2, so the result will return FALSE. If you were to change the formula to =NOT(B2>A5) it would return TRUE and the cell would be formatted.

Note: A common error is to enter your formula into Conditional Formatting without the equals sign (=). If you do this you’ll see that the Conditional Formatting dialog will add the equals sign and quotes to the formula — =»OR(A4>B2,A4

Need more help?

​​​​​​​

See also

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Источник

Function IF in Excel with a few examples of conditions

The logical IF statement in Excel is used for the recording of certain conditions. It compares the number and / or text, function, etc. of the formula when the values correspond to the set parameters, and then there is one record, when do not respond — another.

Logic functions — it is a very simple and effective tool that is often used in practice. Let us consider it in details by examples.

The syntax of the function «IF» with one condition

The operation syntax in Excel is the structure of the functions necessary for its operation data.

Let us consider the function syntax:

  • Boolean – what the operator checks (text or numeric data cell).
  • Value_if_TRUE – what will appear in the cell when the text or numbers correspond to a predetermined condition (true).
  • Value_if_FALSE – what appears in the box when the text or the number does not meet the predetermined condition (false).

Logical IF functions.

The operator checks the A1 cell and compares it to 20. This is a «Boolean». When the contents of the column is more than 20, there is a true legend «greater 20». In the other case it’s «less or equal 20».

Attention! The words in the formula need to be quoted. For Excel to understand that you want to display text values.

Here is one more example. To gain admission to the exam, a group of students must successfully pass a test. The results are listed in a table with columns: a list of students, a credit, an exam.

The statement IF should check not the digital data type but the text. Therefore, we prescribed in the formula В2= «done» We take the quotes for the program to recognize the text correctly.

The function IF in Excel with multiple conditions

Usually one condition for the logic function is not enough. If you need to consider several options for decision-making, spread operators’ IF into each other. Thus, we get several functions IF in Excel.

The syntax is as follows:

Here the operator checks the two parameters. If the first condition is true, the formula returns the first argument is the truth. False — the operator checks the second condition.

Examples of a few conditions of the function IF in Excel:

It’s a table for the analysis of the progress. The student received 5 points:

  • А – excellent;
  • В – above average or superior work;
  • C – satisfactory;
  • D – a passing grade;
  • E – completely unsatisfactory.

IF statement checks two conditions: the equality of value in the cells.

In this example, we have added a third condition, which implies the presence of another report card and «twos». The principle of the operator is the same.

Enhanced functionality with the help of the operators «AND» and «OR»

When you need to check out a few of the true conditions you use the function И. The point is: IF A = 1 AND A = 2 THEN meaning в ELSE meaning с.

OR function checks the condition 1 or condition 2. As soon as at least one condition is true, the result is true. The point is: IF A = 1 OR A = 2 THEN value B ELSE value C.

Functions AND & OR can check up to 30 conditions.

An example of using the operator AND:

It’s the example of using the logical operator OR.

How to compare data in two tables

Users often need to compare the two spreadsheets in an Excel to match. Examples of the «life»: compare the prices of goods in different bringing, to compare balances (accounting reports) in a few months, the progress of pupils (students) of different classes, in different quarters, etc.

To compare the two tables in Excel, you can use the COUNTIFS statement. Consider the order of application functions.

For example, consider the two tables with the specifications of various food processors. We planned allocation of color differences. This problem in Excel solves the conditional formatting.

Baseline data (tables, which will work with):

Select the first table. Conditional Formatting — create a rule — use a formula to determine the formatted cells:

In the formula bar write: = COUNTIFS (comparable range; first cell of first table)=0. Comparing range is in the second table.

To drive the formula into the range, just select it first cell and the last. «= 0» means the search for the exact command (not approximate) values.

Choose the format and establish what changes in the cell formula in compliance. It’s better to do a color fill.

Select the second table. Conditional Formatting — create a rule — use the formula. Use the same operator (COUNTIFS). For the second table formula:

Now it is easy to compare the characteristics of the data in the table.

Источник

The IF function allows you to make a logical comparison between a value and what you expect by testing for a condition and returning a result if that condition is True or False.

  • =IF(Something is True, then do something, otherwise do something else)

But what if you need to test multiple conditions, where let’s say all conditions need to be True or False (AND), or only one condition needs to be True or False (OR), or if you want to check if a condition does NOT meet your criteria? All 3 functions can be used on their own, but it’s much more common to see them paired with IF functions.

Use the IF function along with AND, OR and NOT to perform multiple evaluations if conditions are True or False.

Syntax

  • IF(AND()) — IF(AND(logical1, [logical2], …), value_if_true, [value_if_false]))

  • IF(OR()) — IF(OR(logical1, [logical2], …), value_if_true, [value_if_false]))

  • IF(NOT()) — IF(NOT(logical1), value_if_true, [value_if_false]))

Argument name

Description

logical_test (required)

The condition you want to test.

value_if_true (required)

The value that you want returned if the result of logical_test is TRUE.

value_if_false (optional)

The value that you want returned if the result of logical_test is FALSE.

Here are overviews of how to structure AND, OR and NOT functions individually. When you combine each one of them with an IF statement, they read like this:

  • AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False)

  • OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False)

  • NOT – =IF(NOT(Something is True), Value if True, Value if False)

Examples

Following are examples of some common nested IF(AND()), IF(OR()) and IF(NOT()) statements. The AND and OR functions can support up to 255 individual conditions, but it’s not good practice to use more than a few because complex, nested formulas can get very difficult to build, test and maintain. The NOT function only takes one condition.

Examples of using IF with AND, OR and NOT to evaluate numeric values and text

Here are the formulas spelled out according to their logic:

Formula

Description

=IF(AND(A2>0,B2<100),TRUE, FALSE)

IF A2 (25) is greater than 0, AND B2 (75) is less than 100, then return TRUE, otherwise return FALSE. In this case both conditions are true, so TRUE is returned.

=IF(AND(A3=»Red»,B3=»Green»),TRUE,FALSE)

If A3 (“Blue”) = “Red”, AND B3 (“Green”) equals “Green” then return TRUE, otherwise return FALSE. In this case only the first condition is true, so FALSE is returned.

=IF(OR(A4>0,B4<50),TRUE, FALSE)

IF A4 (25) is greater than 0, OR B4 (75) is less than 50, then return TRUE, otherwise return FALSE. In this case, only the first condition is TRUE, but since OR only requires one argument to be true the formula returns TRUE.

=IF(OR(A5=»Red»,B5=»Green»),TRUE,FALSE)

IF A5 (“Blue”) equals “Red”, OR B5 (“Green”) equals “Green” then return TRUE, otherwise return FALSE. In this case, the second argument is True, so the formula returns TRUE.

=IF(NOT(A6>50),TRUE,FALSE)

IF A6 (25) is NOT greater than 50, then return TRUE, otherwise return FALSE. In this case 25 is not greater than 50, so the formula returns TRUE.

=IF(NOT(A7=»Red»),TRUE,FALSE)

IF A7 (“Blue”) is NOT equal to “Red”, then return TRUE, otherwise return FALSE.

Note that all of the examples have a closing parenthesis after their respective conditions are entered. The remaining True/False arguments are then left as part of the outer IF statement. You can also substitute Text or Numeric values for the TRUE/FALSE values to be returned in the examples.

Here are some examples of using AND, OR and NOT to evaluate dates.

Examples of using IF with AND, OR and NOT to evaluate dates

Here are the formulas spelled out according to their logic:

Formula

Description

=IF(A2>B2,TRUE,FALSE)

IF A2 is greater than B2, return TRUE, otherwise return FALSE. 03/12/14 is greater than 01/01/14, so the formula returns TRUE.

=IF(AND(A3>B2,A3<C2),TRUE,FALSE)

IF A3 is greater than B2 AND A3 is less than C2, return TRUE, otherwise return FALSE. In this case both arguments are true, so the formula returns TRUE.

=IF(OR(A4>B2,A4<B2+60),TRUE,FALSE)

IF A4 is greater than B2 OR A4 is less than B2 + 60, return TRUE, otherwise return FALSE. In this case the first argument is true, but the second is false. Since OR only needs one of the arguments to be true, the formula returns TRUE. If you use the Evaluate Formula Wizard from the Formula tab you’ll see how Excel evaluates the formula.

=IF(NOT(A5>B2),TRUE,FALSE)

IF A5 is not greater than B2, then return TRUE, otherwise return FALSE. In this case, A5 is greater than B2, so the formula returns FALSE.

Example of the Evaluate Formula Wizard

Using AND, OR and NOT with Conditional Formatting

You can also use AND, OR and NOT to set Conditional Formatting criteria with the formula option. When you do this you can omit the IF function and use AND, OR and NOT on their own.

From the Home tab, click Conditional Formatting > New Rule. Next, select the “Use a formula to determine which cells to format” option, enter your formula and apply the format of your choice.

Conditional Formatting > Edit Rule dialog showing the Formula method

Using the earlier Dates example, here is what the formulas would be.

Example of using AND, OR and NOT as Conditional Formatting tests

Formula

Description

=A2>B2

If A2 is greater than B2, format the cell, otherwise do nothing.

=AND(A3>B2,A3<C2)

If A3 is greater than B2 AND A3 is less than C2, format the cell, otherwise do nothing.

=OR(A4>B2,A4<B2+60)

If A4 is greater than B2 OR A4 is less than B2 plus 60 (days), then format the cell, otherwise do nothing.

=NOT(A5>B2)

If A5 is NOT greater than B2, format the cell, otherwise do nothing. In this case A5 is greater than B2, so the result will return FALSE. If you were to change the formula to =NOT(B2>A5) it would return TRUE and the cell would be formatted.

Note: A common error is to enter your formula into Conditional Formatting without the equals sign (=). If you do this you’ll see that the Conditional Formatting dialog will add the equals sign and quotes to the formula — =»OR(A4>B2,A4<B2+60)», so you’ll need to remove the quotes before the formula will respond properly.

Need more help?

Connect with an expert. Learn from live instructors.​​​​​​​

See also

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Learn how to use nested functions in a formula

IF function

AND function

OR function

NOT function

Overview of formulas in Excel

How to avoid broken formulas

Detect errors in formulas

Keyboard shortcuts in Excel

Logical functions (reference)

Excel functions (alphabetical)

Excel functions (by category)

The logical IF statement in Excel is used for the recording of certain conditions. It compares the number and / or text, function, etc. of the formula when the values correspond to the set parameters, and then there is one record, when do not respond — another.

Logic functions — it is a very simple and effective tool that is often used in practice. Let us consider it in details by examples.



The syntax of the function «IF» with one condition

The operation syntax in Excel is the structure of the functions necessary for its operation data.

=IF(boolean;value_if_TRUE;value_if_FALSE)

Let us consider the function syntax:

  • Boolean – what the operator checks (text or numeric data cell).
  • Value_if_TRUE – what will appear in the cell when the text or numbers correspond to a predetermined condition (true).
  • Value_if_FALSE – what appears in the box when the text or the number does not meet the predetermined condition (false).

Example:

Example.

Logical IF functions.

The operator checks the A1 cell and compares it to 20. This is a «Boolean». When the contents of the column is more than 20, there is a true legend «greater 20». In the other case it’s «less or equal 20».

Attention! The words in the formula need to be quoted. For Excel to understand that you want to display text values.

Here is one more example. To gain admission to the exam, a group of students must successfully pass a test. The results are listed in a table with columns: a list of students, a credit, an exam.

list.

The statement IF should check not the digital data type but the text. Therefore, we prescribed in the formula В2= «done» We take the quotes for the program to recognize the text correctly.



The function IF in Excel with multiple conditions

Usually one condition for the logic function is not enough. If you need to consider several options for decision-making, spread operators’ IF into each other. Thus, we get several functions IF in Excel.

The syntax is as follows:

Here the operator checks the two parameters. If the first condition is true, the formula returns the first argument is the truth. False — the operator checks the second condition.

Examples of a few conditions of the function IF in Excel:

few conditions.

It’s a table for the analysis of the progress. The student received 5 points:

  • А – excellent;
  • В – above average or superior work;
  • C – satisfactory;
  • D – a passing grade;
  • E – completely unsatisfactory.

IF statement checks two conditions: the equality of value in the cells.

two conditions.

In this example, we have added a third condition, which implies the presence of another report card and «twos». The principle of the operator is the same.

Enhanced functionality with the help of the operators «AND» and «OR»

When you need to check out a few of the true conditions you use the function И. The point is: IF A = 1 AND A = 2 THEN meaning в ELSE meaning с.

OR function checks the condition 1 or condition 2. As soon as at least one condition is true, the result is true. The point is: IF A = 1 OR A = 2 THEN value B ELSE value C.

Functions AND & OR can check up to 30 conditions.

An example of using the operator AND:

operator AND.

It’s the example of using the logical operator OR.

example of using OR.

How to compare data in two tables

Users often need to compare the two spreadsheets in an Excel to match. Examples of the «life»: compare the prices of goods in different bringing, to compare balances (accounting reports) in a few months, the progress of pupils (students) of different classes, in different quarters, etc.

To compare the two tables in Excel, you can use the COUNTIFS statement. Consider the order of application functions.

For example, consider the two tables with the specifications of various food processors. We planned allocation of color differences. This problem in Excel solves the conditional formatting.

Baseline data (tables, which will work with):

tables.

Select the first table. Conditional Formatting — create a rule — use a formula to determine the formatted cells:

formatted cells.

In the formula bar write: = COUNTIFS (comparable range; first cell of first table)=0. Comparing range is in the second table.

To drive the formula into the range, just select it first cell and the last. «= 0» means the search for the exact command (not approximate) values.

Choose the format and establish what changes in the cell formula in compliance. It’s better to do a color fill.

Select the second table. Conditional Formatting — create a rule — use the formula. Use the same operator (COUNTIFS). For the second table formula:

Download all examples in Excel

compare the characteristics.

Now it is easy to compare the characteristics of the data in the table.

In this article, we will compare dates using the IF function in Excel 2016. IF function works on the logic test and returns the output on the basis of the test.

IF function tests the condition and returns value either it’s True or False.

Syntax of IF function:

=IF(Logic_test,[value_if_true],[Value_if_false])

Here is an example to show how to compare dates in excel. How do we check if  dates are greater than or equal to, does not equal to, less than, etc in excel

We have two lists named Date Column 1 and Date Column 2. We will compare the two lists using the IF function.

Compare date 1

Now we will use the IF function in C2 cell
Formula:

=IF( A2<B2 , «No» , «Yes» )

A2<B2  logic_test to compare dates and returns the values corresponding to it.
“No” value returned if the condition comes True
«Yes» value returned if the condition comes False

Compare date 2

Copy the formula in other cells, select the cells taking the first cell where the formula is already applied, use shortcut key Ctrl+ D.

Your Formula will be pasted using the shortcut and the resulting output will be as shown below.

Compare date 3

If Dates in Column 2 is greater than Dates in Column 1, No is the response or else then Yes is the response as shown in the above image.

This was an example showing one of the features of the IF function in Excel 2016. Please find more Logic_test function here. If you have any query about the IF function, please do share it in the comment box below. We will help you.

Related Articles:

IF not this or that in Microsoft Excel

Count cells if less than value

IF and Conditional formatting

Popular Articles:

50 Excel Shortcuts to Increase Your Productivity

The VLOOKUP Function in Excel

COUNTIF in Excel 2016

How to Use SUMIF Function in Excel

When you’re working with data in Excel, sooner or later you will have to compare data. This could be comparing two columns or even data in different sheets/workbooks.

In this Excel tutorial, I will show you different methods to compare two columns in Excel and look for matches or differences.

There are multiple ways to do this in Excel and in this tutorial I will show you some of these (such as comparing using VLOOKUP formula or IF formula or Conditional formatting).

So let’s get started!

Compare Two Columns (Side by Side)

This is the most basic type of comparison where you need to compare a cell in one column with the cell in the same row in another column.

Suppose you have a dataset as shown below and you simply want to check whether the value in column A in a specific cell is the same (or different) when compared with the value in the adjacent cell.

Compare-Two-Columns-in-Excel-for-matches-dataset

Of course, you can do this when you have a small dataset when you have a large one, you can use a simple comparison formula to get this done. And remember, there is always a chance of human error when you do this manually.

So let me show you a couple of easy ways to do this.

Compare Side by Side Using the Equal to Sign Operator

Suppose you have the below dataset and you want to know what rows have the matching data and what rows have different data.

Compare-Two-Columns-in-Excel-for-matches-dataset

Below is a simple formula to compare two columns (side by side):

=A2=B2

Formula-to-compare-two-cells-side-by-side

The above formula will give you a TRUE if both the values are the same and FALSE in case they are not.

Now, if you need to know all the values that match, simply apply a filter and only show all the TRUE values. And if you want to know all the values that are different, filter all the values that are FALSE (as shown below):

Filtered-to-find-differences

When using this method to do column comparison in Excel, it’s always best to check that your data does not have any leading or trailing spaces. If these are present, despite having the same value, Excel will show them as different. Here is a great guide on how to remove leading and trailing spaces in Excel.

Compare Side by Side Using the IF Function

Another method that you can use to compare two columns can be by using the IF function.

This is similar to the method above where we used the equal to (=) operator, with one added advantage. When using the IF function, you can choose the value you want to get when there are matches or differences.

For example, if there is a match, you can get the text “Match” or can get a value such as 1. Similarly, when there is a mismatch, you can program the formula to give you the text “Mismatch” or give you a 0 or blank cell.

Below is the IF formula that returns ‘Match’ when the two cells have the cell value and ‘Not a Match’ when the value is different.

=IF(A2=B2,"Match","Not a Match")

Compare-columns-using-the-IF-formula

The above formula uses the same condition to check whether the two cells (in the same row) have matching data or not (A2=B2). But since we are using the IF function, we can ask it to return a specific text in case the condition is True or False.

Once you have the formula results in a separate column, you can quickly filter the data and get rows that have the matching data or rows with mismatched data.

Also read: Does Not Equal Operator in Excel (Examples)

Highlight Rows with Matching Data (or Different Data)

Another great way to quickly check the rows that have matching data (or have different data), is to highlight these rows using conditional formatting.

You can do both – highlight rows that have the same value in a row as well as the case when the value is different.

Suppose you have a dataset as shown below and you want to highlight all the rows where the name is the same.

Compare-names-in-two-columns

Below are the steps to use conditional formatting to highlight rows with matching data:

  1. Select the entire dataset (except the headers)
  2. Click the Home tabClick-the-Home-tab
  3. In the Styles group, click on Conditional FormattingClick-on-Conditional-Formatting
  4. In the options that show up, click on ‘New Rule’Click-on-New-Rule
  5. In the ‘New Formatting Rule’ dialog box, click on the option -”Use a formula to determine which cells to format’Click-on-Use-a-formula-to-determine-which-cells-to-format
  6. In the ‘Format values where this formula is true’ field, enter the formula: =$A2=$B2Enter-the-formula-in-Conditional-Formatting-dialog-box
  7. Click on the Format buttonClick-on-the-Format-button
  8. Click on the ‘Fill’ tab and select the color in which you want to highlight the rows with the same value in both columnsSelect-the-color-from-Fill-tab
  9. Click OK

The above steps would instantly highlight the rows where the name is the same in both columns A and B (in the same row). And in the case where the name is different, those rows will not be highlighted.

Compare-two-columns-and-highlight-matching-cells

In case you want to compare two columns and highlight rows where the names are different, use the below formula in the conditional formatting dialog box (in step 6).

=$A2<>$B2

How does this work?

When we use conditional formatting with a formula, it only highlights those cells where the formula is true.

When we use $A2=$B2, it will check each cell (in both columns) and see whether the value in a row in column A is equal to the one in column B or not.

In case it’s an exact match, it will highlight it in the specified color, and in case it doesn’t match, it will not.

The best part about conditional formatting is that it doesn’t require you to use a formula in a separate column. Also, when you apply the rule on a dataset, it remains dynamic. This means that if you change any name in the dataset, conditional formatting will accordingly adjust.

Compare Two Columns Using VLOOKUP (Find Matching/Different Data)

In the above examples, I showed you how to compare two columns (or lists) when we are just comparing side by side cells.

In reality, this is rarely going to be the case.

In most cases, you will have two columns with data and you would have to find out whether a data point in one column exists in the other column or not.

In such cases, you can’t use a simple equal-to sign or even an IF function.

You need something more powerful…

… something that’s right up VLOOKUP’s alley!

Let me show you two examples where we compare two columns in Excel using the VLOOKUP function to find matches and differences.

Compare Two Columns Using VLOOKUP and Find Matches

Suppose we have a dataset as shown below where we have some names in columns A and B.

Compare-names-in-two-columns

If you have to find out what are the names that are in column B that are also in column A, you can use the below VLOOKUP formula:

=IFERROR(VLOOKUP(B2,$A$2:$A$10,1,0),"No Match")

Compare-Two-columns-to-get-matching-data-using-vlookup

The above formula compares the two columns (A and B) and gives you the name in case the name is in column B as well A, and it returns “No Match” in case the name is in Column B and not in Column A.

By default, the VLOOKUP function will return a #N/A error in case it doesn’t find an exact match. So to avoid getting the error, I have wrapped the VLOOKUP function in the IFERROR function, so that it gives “No Match” when the name is not available in column A.

You can also do the other way round comparison – to check whether the name is in Column A as well as Column B. The below formula would do that:

=IFERROR(VLOOKUP(A2,$B$2:$B$6,1,0),"No Match")

Compare Two Columns Using VLOOKUP and Find Differences (Missing Data Points)

While in the above example, we checked whether the data in one column was there in another column or not.

You can also use the same concept to compare two columns using the VLOOKUP function and find missing data.

Suppose we have a dataset as shown below where we have some names in columns A and B.

Compare-two-columns-in-Excel-using-VLOOKUP-Dataset

If you have to find out what are the names that are in column B that not there in column A, you can use the below VLOOKUP formula:

=IF(ISERROR(VLOOKUP(B2,$A$2:$A$10,1,0)),"Not Available","Available")

Compare-Two-columns-to-get-missing-data-using-vlookup

The above formula checks the name in column B against all the names in Column A. In case it finds an exact match, it would return that name, and in case it doesn’t find and exact match, it will return the #N/A error.

Since I am interested in finding the missing names that are there is column B and not in column A, I need to know the names that return the #N/A error.

This is why I have wrapped the VLOOKUP function in the IF and ISERROR functions. This whole formula gives the value – “Not Available” when the name is missing in Column A, and “Available” when it’s present.

To know all the names that are missing, you can filter the result column based on the “Not Available” value.

You can also use the below MATCH function to get the same result:

=IF(ISNUMBER(MATCH(B2,$A$2:$A$10,0)),"Available","Not Available")

Common Queries when Comparing Two Columns

Below are some common queries I usually get when people are trying to compare data in two columns in Excel.

Q1. How to compare multiple columns in Excel in the same row for matches? Count the total duplicates also.

Ans. We have given the procedure to compare two columns in excel for the same row above. But if you want to compare multiple columns in excel for the same row then see the example

=IF(AND(A2=B2, A2=C2),"Full Match", "")

Here we have compared data of column A, column B, and column C. After this, I have applied the above formula in column D and get the result.

Excel-compare-two-columns

Now to count the duplicates, you need to use the Countif function.

=IF(COUNTIF($A2:$E2, $A2)=5, "Full Match", "")

Q2. Which operator do you use for matches and differences?

Ans. Below are the operators to use:

  • To find matches, use the equal to sign (=)
  • To find differences (mismatches), use the not-equal-to sign (<>)

Q3. How to compare two different tables and pull matching data?

Ans. For this, you can use the VLOOKUP function or INDEX & MATCH function. To understand this thing in a better way we will take an example.

Here we will take two tables and now want to do pull matching data. In the first table, you have a dataset and in the second table, take the list of fruits and then use pull matching data in another column. For pull matching, use the formula

=INDEX($B$2:$B$6,MATCH($D2,$A$2:$A$6,0))

Index

Q4. How to remove duplicates in Excel?

Ans. To remove duplicate data you need to first find the duplicate values.

To find the duplicate, you can use various methods like conditional formatting, Vlookup, If Statement, and many more. Excel also has an in-built tool where you can just select the data, and remove the duplicates from a column or even multiple columns

Q5. I can see that there is a matching value in both columns. However, the formulas you have shared above are not considering these as exact matches. Why?

Ans: Excel considers something an exact match when each and every character of one cell is equal to the other. There is a high chance that in your dataset there are leading or trailing spaces.

Although these spaces may still make the values seem equal to a naked eye, for Excel these are different. If you have such a dataset, it’s best to get rid of these spaces (you can use Excel functions such as TRIM for this).

Q7. How to compare two columns that give the result as TRUE when all first columns’ integer values are not less than the second column’s integer values. To solve this problem, I do not require conditional formatting, Vlookup function, If Statement, and any other formulas. I need the formula to solve this problem.

Ans. You can use the array formula for solving this problem.

The syntax is {=AND(H6:H12>I6:I12)}. This will give you “True” as a result whenever the value of Column H is greater than the value in column I else “False” will be the result.

You may also like the following Excel tutorials:

  • Compare Two Columns in Excel (for matches and differences)
  • How to Remove Blank Columns in Excel? (Formula + VBA)
  • How to Hide Columns Based On Cell Value in Excel
  • How to Split One Column into Multiple Columns in Excel
  • How to Select Alternate Columns in Excel (or every Nth Column)
  • How to Paste in a Filtered Column Skipping the Hidden Cells
  • Best Excel Books (that will make you an Excel Pro)
  • How to Flip Data in Excel (Columns, Rows, Tables)?
  • Find the Closest Match in Excel (Nearest Value)
  • How to Compare Two Cells in Excel?
  • VLOOKUP Not Working – 7 Possible Reasons + How to Fix!

Two columns in excel are compared when their entries are studied for similarities and differences. The similarities are the data values that exist in the same row of both the compared columns. In contrast, the differences are those values that exist in only one of these columns.

For example, for a specific month, a table displays the following information:

  • Column A lists the names of the employees who took three consecutive leaves.
  • Column B lists the names of the employees who took two consecutive leaves.

Since the data pertains to the same organization, there can be a similarity or a difference within the given set of values. The same is explained as follows:

  • A similarity or a match (column A is equal to column B) implies employees who took both three and two continuous leaves.
  • A difference (column A is not equal to column B) implies employees who took either three or two continuous leaves.

It is difficult to scan through the data to track the matches and the differences manually. Hence, there are techniques which can be followed to compare 2 columns of an excel worksheet.

Table of contents
  • Compare two Columns in Excel
    • How to Compare two Columns in Excel? (Top 4 Methods)
      • #1 – Compare Using Simple Formulae
      • #2 – Compare 2 Columns Using the IF Formula
      • #3 – Compare Using the EXACT Formula
      • #4 – Compare 2 Excel Columns Using Conditional Formatting
    • The Properties of the Comparison Methods
    • Frequently Asked Questions
    • Recommended Articles

How to Compare two Columns in Excel? (Top 4 Methods)

The top four methods to compare 2 columns are listed as follows:

  • Method #1–Compare using simple formulae
  • Method #2–Compare using the IF formula
  • Method #3–Compare using the EXACT formula
  • Method #4–Compare using conditional formatting

Let us understand these methods with the help of examples.

You can download this Compare Two Columns Excel Template here – Compare Two Columns Excel Template

#1 – Compare Using Simple Formulae

The following table shows the names of the employees of an organization in column A. Columns B and C display their log-in and the log-out times respectively.

We want to compare two excel columns B and C to find out the employees who forgot to logout from the office. The official timings are 10:30 a.m.-7:30 p.m. Use the formula method for comparison.

Compare Two Columns Method 1

For the given data, if the log-in time is equal to the log-out time, we assume that the employee has forgotten to logout.

The steps to compare two columns in excel with the help of the comparison operator “equal to” (=) are listed as follows:

  1. In cell D2, enter the symbol “=” followed by selecting the cell B2.

    Compare Two Columns Method 1-1

  2. Enter the symbol “=” again, followed by selecting the cell C2.

    Compare Two Columns Method 1-2

  3. Press the “Enter” key. It returns “false.” This implies that the value in cell B2 is not equal to that of cell C2.

    Compare Two Columns Method 1-3

  4. Drag or copy-paste the formula to the remaining cells. The output is either “true” or “false,” as shown in the following image.
    If the value in column B is equal to that of column C, the result is “true,” else “false.” The cells D5 and D9 show the output “true.”
    Hence, Roshan and Uday forgot to logout from the office.

    Compare Two Columns Method 1-4

#2 – Compare 2 Columns Using the IF Formula

Working on the data of example #1, we want the following results:

  • “Forgot to punch out,” if the employee forgets to logout
  • “No problem,” if the employee logs out

Use the IF functionIF function in Excel evaluates whether a given condition is met and returns a value depending on whether the result is “true” or “false”. It is a conditional function of Excel, which returns the result based on the fulfillment or non-fulfillment of the given criteria.
read more
to compare the columns B and C.

We apply the following formula.

“=IF(B2=C2,“Forgot to Punch Out”,“No Problem”)”

If the value in column B is equal to that of column C, the result is “true,” otherwise “false.” For every “true” value, the formula returns “forgot to punch out.” Likewise, it returns “no problem” for every “false” value.

The output is shown in column E of the following image.

Hence, Roshan and Uday are the only two employees who have forgotten to logout from the office.

Compare Two Columns Method 2

#3 – Compare Using the EXACT Formula

Working on the data of example #1, we want to compare the two excel columns B and C with the help of the EXACT functionThe exact function is a logical function in excel used to compare two strings or data with each other, and it gives us the result whether the both data are an exact match or not. This function is a logical function, so it provides true or false as a result.read more.

We apply the following formula.

“=EXACT(B2,C2)”

If the value in column B is equal to that of column C, the formula returns “true,” otherwise “false.” The output is shown in column F of the following image.

Hence, the entries of columns B and C are identical for Roshan and Uday.

Note: The EXACT function is case-sensitive.

Compare Two Columns Method 3

We have written the name “Raman” in columns A and B with different casing. We apply the following formula.

“=EXACT(A2,B2)”

The formula returns “false” when the casing of cell A2 is different from that of cell B2. Likewise, it returns “true” if the casing in columns A and B is the same.

The output is shown in column C of the following image.

Compare Two Columns Method 3-1

#4 – Compare 2 Excel Columns Using Conditional Formatting

Working on the data of example #1, we want to highlight those entries that are identical in columns B and C. Use the conditional formattingConditional formatting is a technique in Excel that allows us to format cells in a worksheet based on certain conditions. It can be found in the styles section of the Home tab.read more feature.

Compare Two Columns Method 4

Step 1: Select the entire data. In the Home tab, click the “conditional formatting” drop-down under the “styles” section. Select “new rule.”

Compare Two Columns Method 4-1

Step 2: The “new formatting rule” window appears. Under “select a rule type,” choose the option “use a formula to determine which cells to format.”

Method 4-2

Step 3: Enter the formula “$B2=$C2” under “edit the rule description.”

Method 4-3

Step 4: Click “format.” In the “format cells” window, select the color to highlight the identical entries. Click “Ok.” Click “Ok” again in the “new formatting rule” window.

Method 4-4

Step 5: The matches of columns B and C are highlighted, as shown in the following image.

Hence, the entries of columns B and C are identical for Roshan and Uday.

Method 4-5

The Properties of the Comparison Methods

The features of the comparison methods discussed are listed as follows:

  • The outcomes of the IF function can be modified according to the requirement of the user.
  • The EXACT function returns “false” for two same values having different casing.
  • The simplest technique to compare two excel columns is by using the comparison operator “equal to” (method #1).

Note: The comparison method to be used depends on the data structure and the kind of output required.

Frequently Asked Questions

1. What does it mean to compare two columns and how is it done in Excel?

The comparison of two data columns helps find the similarities and the differences. In case of similarity, a value exists in the same row of both the columns. In contrast, a difference is a deviation of one value from the other.

To compare two excel columns, the easiest approach is listed as follows:
a. Enter the following formula.
“=cell1=cell2”
The “cell1” is a cell containing a data value in the first column. The “cell2” is a cell containing a data value in the second column. Both “cell1” and “cell2” are in the same row.
b. Press the “Enter” key.
The formula returns “true” or “false” depending on whether the value exists in both the compared columns or not.

2. How to highlight the different values of two columns without using the formula in Excel?

Let us compare the following 2 columns consisting of names in the mentioned sequence:
• Column A contains Jack, Adam, Elizabeth, Betty, and Veronica.
• Column B contains Robert, Peter, Elizabeth, Henry, and Veronica.

The steps to highlight the different values without using the formula are listed as follows:

a. Select columns A and B.
b. In the Home tab, click “find and select” drop-down under the “editing” group. Choose “go to special.”
c. In the “go to special” window, select “row differences.” Click “Ok.”

The names Robert, Peter, and Henry of column B are highlighted. These cells can be colored using the “fill color” property of Excel.

3. How to compare multiple columns in Excel?

Let us compare the following columns consisting of numbers in the mentioned sequence:

• Column A contains 3, 49, 20, 22, and 86 in the range A1:A5.
• Column B contains 29, 49, 38, 21, and 86 in the range B1:B5.
• Column C contains 12, 49, 56, 24, and 86 in the range C1:C5.

The steps to compare columns A, B, and C are stated as follows:

a. Enter the following formula in cell D1. “IF(COUNTIF($A1:$C5,$A1)=3,“full match”,“”)”
b. Press the “Enter” key.
c. Drag or copy-paste the formula to the remaining cells.

Since we are comparing three excel columns, we enter the number 3 in the formula. The formula returns “full match” in cells D2 and D5. It returns an empty string in the cells D1, D3, and D4.

Hence, the numbers 49 and 86 appear in the respective rows 2 and 5 of all the three columns.

Recommended Articles

This has been a guide to compare two columns in Excel. Here we discussed the top 4 methods to compare 2 columns in Excel, 1) the operator “equal to”, 2) IF function, 3) EXACT formula, and 4) conditional formatting. We also went through some practical examples. You can download the Excel template from the website. For more on Excel, take a look at the following articles-

  • Freeze Columns in ExcelFreezing columns in excel fixes or locks them so that they remain visible while scrolling through the database. A frozen column does not move with the movement of the remaining columns.read more
  • Excel Rows to ColumnsRows can be transposed to columns by using paste special method and the data can be linked to the original data by simply selecting ‘Paste Link’ form the paste special dialog box. It could also be done by using INDIRECT formula and ADDRESS functions.read more
  • Count Only Unique Values in ExcelIn Excel, there are two ways to count values: 1) using the Sum and Countif function, and 2) using the SUMPRODUCT and Countif function.read more
  • Advanced Filter in ExcelThe advanced filter is different from the auto filter in Excel. This feature is not like a button that one can use with a single click of the mouse. To use an advanced filter, we have to define criteria for the auto filter and then click on the “Data” tab. Then, in the advanced section for the advanced filter, we will fill our criteria for the data.read more

(Note: This guide on Excel string compare is suitable for all Excel versions including Office 365)

Excel is a very reliable spreadsheet tool. In spite of this, errors can creep in due to human oversight. And some of these errors can make or break your database. 

Let us say, for example, you have a list of blacklisted contacts. Now, somebody from your sales team accidentally mixed up the list with good leads. What do you do now? 

While you can technically check the names one by one, it is practically impossible to compare hundreds of names manually. That’s why we need a fast but reliable way to compare strings in Excel. 

Fortunately, Excel has built-in features and functions that can easily compare strings. In this guide, let us explore them. 

You’ll learn:

  1. Method 1: How to Compare Two Case Insensitive Strings? 
  2. Method 2: How to Compare Two Case Sensitive Strings?
  3. Method 3: How to Compare Two Strings Using VBA? 
  4. Method 4: How to Compare Strings Using Conditional Formatting?
  5. Method 5: How to Compare Strings for Similarity?

Related:

How to Remove Spaces in Excel? 3 Easy Methods

How to Insert Bullet Points in Excel? 5 Easy Methods

How to Set Print Area in Excel? Step-by-Step Guide

Method 1: How to Compare Two Case Insensitive Strings? 

To compare two strings, you can simply use the formula IF(A2=B2, “Equal”, “Error”) and drag it to the rest of the cells, provided you don’t care about the cases. 

Excel string compare using the IF function
Excel string compare using the IF function

If necessary, you can later filter similar strings and delete them. Please note that this “IF” function compares strings, numbers, dates, boolean expressions, etc. 

Method 2: How to Compare Two Case Sensitive Strings?

In case, you want to compare strings while accounting for different upper and lower case versions use the EXACT function. 

Let us see how to do this: 

  1. In a separate column, enter the formula IF(EXACT(D2,E2), “Equal”, “Error”)
  1. This will return “Equal” if the values are exactly the same. Drag the formula to the entire range. 
Case sensitive Excel string compare using IF and EXACT functions
Case sensitive Excel string compare using IF and EXACT functions

Please note that the IF formula is optional and is only used for displaying a message instead of “TRUE” or “FALSE”. 

Also Read:

How to VLOOKUP From Another Sheet?

How to Move Rows in Excel? 5 Easy Methods

How to Fix the Excel Circular Reference Error?

Method 3: How to Compare Two Strings Using VBA? 

Well, the methods discussed above work only if you are comparing simple strings. What if you need to compare complex strings? 

Isn’t there any efficient way to compare strings in Excel? 

Fortunately, we have VBA. Using this VBA code, we can not only compare two strings but also highlight the differences between them. 

Let us see how to do this: 

  1. Open the relevant Excel spreadsheet and press Alt+F11 to go to the VBA editor. 
  1. Here, click on the Module option under Insert 
Click on the Module option under the Insert menu
Click on the Module option under the Insert menu
  1. In the New Module window, paste the following VBA code and run it using the F5 shortcut. 
Sub highlight()
    Dim R1 As Range
    Dim R2 As Range
    Dim Txt As String
    Dim C1 As Range
    Dim C2 As Range
    Dim I As Long
    Dim J As Integer
    Dim xL As Integer
    Dim xD As Boolean
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
      Txt = ActiveWindow.RangeSelection.AddressLocal
    Else
      Txt = ActiveSheet.UsedRange.AddressLocal
    End If
lOne:
    Set R1 = Application.InputBox("Range A:", "Compare_Strings", Txt, , , , , 8)
    If R1 Is Nothing Then Exit Sub
    If R1.Columns.Count > 1 Or R1.Areas.Count > 1 Then
        MsgBox "Multiple ranges or columns have been selected ", vbInformation, "Compare_Stringsl"
        GoTo lOne
    End If
lTwo:
    Set R2 = Application.InputBox("Range B:", "Compare_Strings", "", , , , , 8)
    If R2 Is Nothing Then Exit Sub
    If R2.Columns.Count > 1 Or R2.Areas.Count > 1 Then
        MsgBox "Multiple ranges or columns have been selected ", vbInformation, "Compare_Strings"
        GoTo lTwo
    End If
    If R1.CountLarge <> R2.CountLarge Then
       MsgBox "Two selected ranges must have the same numbers of cells ", vbInformation, "Compare_Strings"
       GoTo lTwo
    End If
    xD = (MsgBox("Yes to Highlight Common String, No to highlight differences ", vbYesNo + vbQuestion, "Compare_Strings") = vbNo)
    Application.ScreenUpdating = False
    R2.Font.ColorIndex = xlAutomatic
    For I = 1 To R1.Count
        Set C1 = R1.Cells(I)
        Set C2 = R2.Cells(I)
        If C1.Value2 = C2.Value2 Then
            If Not xD Then C2.Font.Color = vbGreen
        Else
            xL = Len(C1.Value2)
            For J = 1 To xL
                If Not C1.Characters(J, 1).Text = C2.Characters(J, 1).Text Then Exit For
            Next J
            If Not xD Then
                If J <= Len(C2.Value2) And J > 1 Then
                    C2.Characters(1, J - 1).Font.Color = vbGreen
                End If
            Else
                If J <= Len(C2.Value2) Then
                    C2.Characters(J, Len(C2.Value2) - J + 1).Font.Color = vbRed
                End If
            End If
        End If
    Next
    Application.ScreenUpdating = True
End Sub
  1. In the Compare_Strings dialog box, select the ranges of the strings you want to compare and click OK. 
Select Range A
Select Range A
Select Range B
Select Range B
  1. Choose whether to highlight the differences or the similarities between the strings.  All differences will be highlighted in red and all similarities will be highlighted in green. 

Method 4: How to Compare Strings Using Conditional Formatting?

What if you are in a hurry and want to quickly compare strings for duplicates?

Well, you can take the help of the Conditional Formatting feature to instantly compare and highlight duplicates in Excel. 

To do this, just select the range of cells where you want to look for duplicates and go to Conditional Formatting > Highlight Cell Rules > Duplicate Values. This will highlight all duplicates in this range. 

Highlight duplicates using Conditional Formatting
Highlight duplicates using Conditional Formatting
Equal strings will be highlighted in red
Equal strings will be highlighted in red

Method 5: How to Compare Strings for Similarity? 

If you are looking to find similarities between two sets of un-identical strings, you can use this method. 

Just enter the formula IFERROR( IF (SEARCH (text1, text2),if_true),if_false) in an adjacent column and drag it to the entire range. In this example, we are comparing column D with column E. Hence the formula will be =IFERROR(IF(SEARCH(D2,E2),”Similar”),”Different”)

Using IFERROR to find similar strings
Using IFERROR to find similar strings

This will check if text1 is inside text2 or not and return “Similar” or “Different” accordingly. 

Suggested Reads:

How to Extract an Excel Substring? – 6 Best Methods

Excel Quick Analysis Tool – The Best Guide (5 Examples)

How to Lock Cells in Excel?— 4 Best Methods with Examples

Let’s Wrap Up

In this short guide, we discussed five easy methods to compare strings in Excel. Try each one out and use the one which suits you best. In fact, you can modify some of these methods to your liking. Please let me know if you have any questions in the comments section. 

We are always happy to help. 

Please visit our free resources section for more high-quality Excel guides.

Ready to upskill your Excel knowledge? Simon Sez IT has been teaching Excel for over ten years. For a low, monthly fee you can get access to 130+ training courses. Click here for advanced Excel courses with in-depth training modules.

Simon Calder

Chris “Simon” Calder was working as a Project Manager in IT for one of Los Angeles’ most prestigious cultural institutions, LACMA.He taught himself to use Microsoft Project from a giant textbook and hated every moment of it. Online learning was in its infancy then, but he spotted an opportunity and made an online MS Project course — the rest, as they say, is history!

Skip to content

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

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

Comparing two columns in Excel is something you’d need to do very often. Sometimes to see if both the columns tally. And the other times, to see if both the columns are unique to each other 👀

In both cases, Excel fails to offer any in-built feature to help you do that. Yeah, very unfortunate – but that’s how it is.

However, there are still many hacks that you can use to compare two columns in Excel.

To learn those, continue reading the guide below 👇

Also, download our free sample workbook here to tag along with the guide.

Compare two columns to find matches & differences

Comparing two columns to spot-matching data in Excel is all about putting an IF function in place 😎

For example, the image below has two lists.

Two lists of names

Both lists contain names that apparently seem the same. But we still need to run a check to see if they are actually the same.

Oh no! Don’t start scanning the lists already. We have a hack to do that.

  1. In a neighboring column to the lists (Column C), write the IF function as below:

= IF (

Writing the IF function in a separate column
  1. As the first argument, write in the logical test to be performed by the IF function.

= IF (A2=B2

Specifying the logical test

We want to see if the first and the second list match. And so, we have set the logical test to be performed to Cell A2=B2. Excel would now check if Cell A2 is equal to B2 🚀

  1. As the second argument, type in the value that you’d want to be returned if the logical test turns true (value_if_true).

You can set any value as the value_in_true enclosed in double quotation marks. For now, we are setting it to “Names match”.

= IF (A2=B2, “Names match”

Specifying the value_if_true
  1. For the value_if_false, type in the value that you’d want to be returned if the logical test turns false.

Let’s set it to “Names don’t match”.

= IF (A2=B2, “Names match”, ”Names don’t match”)

Specifying the value_if_false

With this, we are all done writing the IF function 👍

  1. Hit “Enter” to get the results as follows:
Both the cells have the same value

The result is “Names match” for the first row of the list. And we can clearly see the same name “Charles” in both lists.

  1. Drag and drop the formula till the end (until the lists continue).
IF function applied to the whole list

The whole list is now checked for the same data. And for some names (in Rows 3, 4, and 7), the IF function returns “Names don’t match” ❌

Pay attention to the dataset to note that for:

  • Row 3: The spelling of “Tilbury” and “Tillbury” differs.
  • Row 4: “Samia” and “Leon” are clearly two different names.
  • Row 7: “Peter” and “Tim” are clearly two different names.

Kasper Langmann, Microsoft Office Specialist

This is one way how you can compare columns in Excel to know if both of the columns match or not. Such a row-to-row comparison also helps identify the individual items that differ (like Row 3,4, and 7 above) 🚴‍♀️

Compare two columns for case-sensitive matches

Take a quick look at the image below (Row 5).

The text “Pesso” in the first list starts with a capital P. Whereas, the text “pesso” in the second list starts with a small “p” 👆

However, the IF function treats them the same and returns the value “Names Match”.

This means that the IF function performs a case-insensitive comparison. But what if you want to run a case-sensitive comparison of two lists? Not a problem – we can do that too. See below.

  1. Write the EXACT function as below:

= EXACT (A2,B2)

The EXACT function checks if two given cells (A2 and B2) have exactly the same value. It also checks for case sensitivity.

It returns TRUE if both the cells are equal, and FALSE if they are not exactly equal.

EXACT function returns TRUE

For the first row, the EXACT function returned TRUE. That’s because the name “Charles” in the first column is exactly the same as “Charles” in the second column.

  1. Nest the EXACT function above in the IF function as follows.

= IF ( EXACT (A2,B2)

Nesting the EXACT function in the IF function

This will act as the logical test. If the EXACT function returns TRUE, the IF function will return the value_if_true.

And if the EXACT function returns FALSE, the IF function will return the value_if_false 🎯

  1. Type in the value that you’d want to be returned if the EXACT function returns TRUE.

We are again setting it to “Names match”.

= IF ( EXACT (A2,B2), “Names match”

Specifying the value_if_true
  1. Type in the value that you’d want to be returned if the EXACT function returns FALSE.

= IF ( (EXACT(A2, B2), “Names match”, ”Names don’t match”)

Specifying the value_if_false
  1. Hit “Enter”.
The IF function returns the results
  1. Drag and drop the formula to the whole list.
 IF function applied to the whole list

Note that this time, the results for the same Row 5 (Pesso) change 🤩

The IF function now tells us that the names do not match because they do not have the same case.

Highlight matches or differences between two columns

If you don’t want a whole separate list of formulas and results while you compare two columns – no worries, we hear you.

Another efficient way to compare columns is by running conditional formatting in Excel. You can use it to identify matching and differing columns, both 🎨

Let’s see how.

  1. Select the lists that you want to compare. If you don’t want both lists to be highlighted, you may select any one list only.
Selection of multiple columns
  1. Go to Home Tab > Conditional Formatting.
Conditional formatting
  1. From the drop-down list that appears, select Highlight Cell Rules option > More Rules.
More cell highlighting rules

This will take you to the “New Formatting Rule” dialog box as follows:

Highlight cell rules options
  1. Under Rule Type, select “Use a formula to determine which cells to format”.
  2. Under the Rule description, write the following formula:

=$A2=$B2

Setting the formatting rules to compare data

This tells Excel to format the cells where cell A2 is equal to cell B2.

We have turned the column reference into an absolute one so that the same formatting can be applied to the whole list 📝

Kasper Langmann, Microsoft Office Specialist
  1. Click on the “Format” button to select any Format that you’d want to be applied to the cells of the list that match.

We have selected the Fill option in green color as below.

Setting the formatting color
  1. All done – Click “Okay”.
Excel format the cells that have matching values

Excel highlights all the rows that match 📌

Pro Tip!

Did you note Row 5 (Pesso) being highlighted in green? This means conditional formatting also carries out a case-insensitive comparison of columns.

Similarly, if you want to apply conditional formatting to those rows of the lists that do not match:

  1. Launch the “New Formatting Rule” dialog box.
  2. Under Rule Type, select “Use a formula to determine which cells to format”.
  3. Under the Rule description, write the following formula:

=$A2<>$B2

Setting the formatting rules

This tells Excel to format the cells where cell A2 is not equal to (<>) B2.

  1. Choose any Format that you’d want to be applied to the cells that meet the above criterion. Like we are selecting a red fill.
Setting the formatting rules
  1. Press “Enter” and you get the following results.
Excel formats the cells that do not match

This time Excel has red-highlighted the cells that are different in the whole list ⭕

That’s it – Now what?

We hope you now know how to compare columns in Excel – whether to find matching items or unique items.

In the guide above, we’ve explored different functions that can help you do that. We also learned to use conditional formatting to highlight the similarities and differences between any two columns in Excel.

Excel functions and features are super versatile. Even if Excel misses out on a specific function, you can find a way to make that happen by tweaking some other Excel functions.

There are just so many functions in Excel to explore. And once you know them all – there’d be barely anything in Excel you couldn’t do 💪

Want to begin learning them? We suggest you start with the VLOOKUP function, SUMIF, and IF functions of Excel.

My 30-minute free email course teaches all details about these (and other) functions of Excel. Click here to sign up now.

Frequently asked questions

To check if two cells (say Cell A1 and B1) have the same text in Excel, apply the IF function as follows:

= IF (A1=B1, “Same Text”, “Not Same”)

If both the cells have duplicate values, the IF function would return “Same text”. And if there is some difference between both the cells, it will return “Not Same”.

To compare two lists (Say Column A and B) in Excel, apply the IF Function in a cell in Excel as follows:

= IF (A1=B1, “Same”, “Different”)

Drag and drop this formula to the whole list. The IF function will return “Same” for each row of the list that is the same in both columns and “Different” if it’s different.

Kasper Langmann2023-01-11T20:44:56+00:00

Page load link

One area that often troubles Microsoft Excel users is working with dates.

This is mostly because dates can be formatted in many different ways in Excel.

So while you may see two dates in Excel and think those are the same, there is a possibility that these might be different values in the back end (or vice versa, you may think two cells have different dates, and it may be the same).

In this tutorial, I will show you a couple of techniques that you can use to compare dates in Èxcel.

This could be useful when you need to check whether the dates in two cells are the same or not, or if one date is greater than or less than the other date.

So let’s get started!

How does Excel Stores Dates in the Cells?

Before I get into how you can compare two dates in Excel, let me first explain how date and time values are stored in Excel.

This is important, so if you don’t know this already, don’t skip this section (I will keep it short).

Dates are stored as whole numbers in the backend in Excel, and time values are stored as decimal values.

The dates in Excel start from 01 Jan 1900, which means that the value 1, when formatted as a date, would show you 01-01-1900 as the date in the cell in Excel.

Similarly, 44562, would represent 01 Jan 2022 (which means that 44562 days have passed between 01 Jan 1900 and 01 Jan 2022).

Similarly, time is stored as decimal values, where 0.5 would represent 12 hours and 0.75 would represent 18 hours.

So if I have the value 44562.5 in a cell, this would represent 01 Jan 2022 at 12:00 PM.

In a nutshell, dates and time values are stored as numbers in the backend, that are formatted to show as dates and time. This allows users to use these dates and times in calculations.

This is also the reason that not all date formats are acceptable formats in Excel. For example, if you enter Jan 01, 2022 in a cell in Excel, this would be treated as a text string and not as a valid date format.

Comparing Dates in Excel

Now that we have a better understanding of dates and time values are handled in the Excel backend, let’s see how to compare two dates in Excel.

Check Whether the Dates are the Same or Not

Below I have a dataset where I have two sets of dates in two columns, and I want to check whether these dates are the same or not.

Compare Dates dataset

This can be done using a simple equal-to-operator.

=A2=B2
Formula to compare dates in same row

The above formula would return TRUE if the compared dates are the same, and FALSE if they are not.

Since dates are stored as numeric values, when we use this formula, Excel simply checks whether the date numeric value is the same or not.

Comparing dates in Excel is just like comparing two numbers.

A few things important things you must know when comparing dates:

  • Dates can be in two different formats and yet be equal, as the backend numeric values of these dates are the same
  • Dates that look exactly the same can be different. In the above example, look at row #5 and #7. The date looks the same, but the result says FALSE. This happens when the date has a time part as well but it’s formatted to only show the date. In this case, the dates in column B also have some time added to it (but it doesn’t show in the cell).
  • In case you have a date entered as a string, you won’t be able to compare these (your dates needs to be in an acceptable date format)
Also read: How to Change Date Format In Excel?

Compare Dates Using IF Formula (Greater Less/Less Than)

While a head-on comparison with an equal-to operator works fine, your comparison could be more meaningful when you use an IF formula.

Below, I have dates in two different columns, and I want to know whether the dates in column B occurred before or after the dates in column A.

Dataset to compare dates with IF

This will help me identify whether the report was submitted before or after the specified due date.

Below is the formula that will do this:

 =IF(C2<=B2,"In Time","Delayed")
IF formula to compare dates

The above formula compares the two dates using the less than or equal to operator, and if the submission date is before the due date, it shows ‘In Time’, else it shows delayed.

You can do more with the IF formula (such as nesting multiple IF statements in the same formula).

Below is the formula that will show the text Delayed’ if the report is submitted 5 days after the due date, and it will show ‘Grace’ if the report is submitted within 5 days of the due date, and return ‘In-time’ if submitted before the due date (or the last day of submission)

=IF(C2-B2<=0,"In Time",IF(C2-B2<=5,"Grace","Delayed"))

The above formula uses two IF formulas (called nested IF formulas), as we need to check for 3 conditions.

Note that I have subtracted the dates from each other, which is possible as dates are stored as whole numbers in the backend. So when I subtract one date from another, it gives me the total number of days between these two dates.

Compare Dates That Have Time Values

As I mentioned earlier, dates are stored as whole numbers, and time is stored as a decimal number in Excel.

Many times, people format their cells to only show the date and hide the time part.

Below is an example where I have the same values in both columns, but the dates in column B are formatted to only show the date part, so you don’t see the time part in it.

Compare Dates dataset

This can lead to confusion when comparing dates in Excel. For example, below I have a datset, and when I use the equal-to operator to compare the dates in the two columns, I get unexpected results.

Formula to compare dates in same row

In the above, I get a mismatch in cells C5 and C7, while it appears that the dates are the same.

In such a scenario, you can use the INT formula to make sure you’re comparing only the day part of the date and the time part is ignored.

Below is the formula that will give us the right result:

=INT(A2)=INT(B2)
Comparing Dates using the INT formula

The INT part of the formula makes sure that only the completed days are considered while comparing the dates, and the decimal part is ignored.

While this is an uncommon scenario, it is always a good idea to check the cell format when working with dates. I have often found that downloads from several databases that contain date and time values both have cells formatted to only show the date part.

Operators You Can Use When Comparing Dates in Excel

And finally, below are some operators you can use when comparing dates in Excel:

  • Equal to (=)
  • Greater Than (>)
  • Less Than (<)
  • Greater Than or Equal to (>=)
  • Less Than or Equal to (<=)
  • Not Equal to (<>)

In this tutorial, I covered how to compare dates in Excel using simple operators and the IF function. I also covered how to handle comparing dates when you have the time value as a part of it.

I hope you found this tutorial useful!

Other Excel tutorials you may also like:

  • How to Compare Two Excel Sheets (for differences)
  • How to Compare Text in Excel (Easy Formulas)
  • How to Compare Two Columns in Excel (for matches & differences)
  • How to Convert Serial Numbers to Dates in Excel
  • How to SUM values between two dates (using SUMIFS formula)
  • How to Stop Excel from Changing Numbers to Dates Automatically
  • Get Day Name from Date in Excel (Easy Formulas)
  • How to Add Months to Date in Excel (Easy Formula)
  • Combine Date and Time in Excel (Easy Formula)
  • Highlight Dates Before Today in Excel

Понравилась статья? Поделить с друзьями:
  • If and but statement in excel
  • If and but formula in excel
  • If and between formula in excel
  • If and average functions excel
  • If all true excel