Excel logical operators: equal to, not equal to, greater than, less than

Many tasks you perform in Excel involve comparing data in different cells. For this, Microsoft Excel provides six logical operators, which are also called comparison operators. This tutorial aims to help you understand the insight of Excel logical operators and write the most efficient formulas for your data analysis.

Excel logical operators - overview

A logical operator is used in Excel to compare two values. Logical operators are sometimes called Boolean operators because the result of the comparison in any given case can only be either TRUE or FALSE.

Six logical operators are available in Excel. The following table explains what each of them does and illustrates the theory with formula examples.

Condition Operator Formula Example Description
Equal to = =A1=B1 The formula returns TRUE if a value in cell A1 is equal to the values in cell B1; FALSE otherwise.
Not equal to <> =A1<>B1 The formula returns TRUE if a value in cell A1 is not equal to the value in cell B1; FALSE otherwise.
Greater than > =A1>B1 The formula returns TRUE if a value in cell A1 is greater than a value in cell B1; otherwise it returns FALSE.
Less than < =A1<B1 The formula returns TRUE if a value in cell A1 is less than in cell B1; FALSE otherwise.
Greater than or equal to >= =A1>=B1 The formula returns TRUE if a value in cell A1 is greater than or equal to the values in cell B1; FALSE otherwise.
Less than or equal to <= =A1<=B1 The formula returns TRUE if a value in cell A1 is less than or equal to the values in cell B1; FALSE otherwise.

The screenshot below demonstrates the results returned by Equal to, Not equal to, Greater than and Less than logical operators:
Using Equal to, Not equal to, Greater than and Less than in Excel

It may seem that the above table covers it all and there's nothing more to talk about. But in fact, each logical operator has its own specificities and knowing them can help you harness the real power of Excel formulas.

Using "Equal to" logical operator in Excel

The Equal to logical operator (=) can be used to compare all data types - numbers, dates, text values, Booleans, as well as the results returned by other Excel formulas. For example:

=A1=B1 Returns TRUE if the values in cells A1 and B1 are the same, FALSE otherwise.
=A1="oranges" Returns TRUE if cells A1 contain the word "oranges", FALSE otherwise.
=A1=TRUE Returns TRUE if cells A1 contain the Boolean value TRUE, otherwise it returns FALSE.
=A1=(B1/2) Returns TRUE if a number in cell A1 is equal to the quotient of the division of B1 by 2, FALSE otherwise.

Example 1. Using the "Equal to" operator with dates

You might be surprised to know that the Equal to logical operator cannot compare dates as easily as numbers. For example, if the cells A1 and A2 contain the date "12/1/2014", the formula =A1=A2 will return TRUE exactly as it should.

However, if you try either =A1=12/1/2014 or =A1="12/1/2014" you will get FALSE as the result. A bit unexpected, eh?

The point is that Excel stores dates as numbers beginning with 1-Jan-1900, which is stored as 1. The date 12/1/2014 is stored as 41974. In the above formulas, Microsoft Excel interprets "12/1/2014" as a usual text string, and since "12/1/2014" is not equal to 41974, it returns FALSE.

To get the correct result, you must always wrap a date in the DATEVALUE function, like this =A1=DATEVALUE("12/1/2014")
Using Excel's equal to operator with dates

Note. The DATEVALUE function needs to be used with other logical operator as well, as demonstrated in the examples that follow.

The same approach should be applied when you use Excel's equal to operator in the logical test of the IF function. You can find more info as well as a few formula examples in this tutorial: Using Excel IF function with dates.

Example 2. Using the "Equal to" operator with text values

Using Excel's Equal to operator with text values does not require any extra twists. The only thing you should keep in mind is that the Equal to logical operator in Excel is case-insensitive, meaning that case differences are ignored when comparing text values.

For example, if cell A1 contains the word "oranges" and cell B1 contains "Oranges", the formula =A1=B1 will return TRUE.

If you want to compare text values taking in to account their case differences, you should use the EXACT function instead of the Equal to operator. The syntax of the EXACT function is as simple as:

EXACT(text1, text2)

Where text 1 and text2 are the values you want to compare. If the values are exactly the same, including case, Excel returns TRUE; otherwise, it returns FALSE. You can also use the EXACT function in IF formulas when you need a case-sensitive comparison of text values, as shown in the below screenshot:
Using the EXACT function for case-sensitive comparison of text values

Note. If you want to compare the length of two text values, you can use the LEN function instead, for example =LEN(A2)=LEN(B2) or =LEN(A2)>=LEN(B2).

Example 3. Comparing Boolean values and numbers

There is a widespread opinion that in Microsoft Excel the Boolean value of TRUE always equates to 1 and FALSE to 0. However, this is only partially true, and the key word here is "always" or more precisely "not always" : )

When writing an 'equal to' logical expression that compares a Boolean value and a number, you need to specifically point out for Excel that a non-numeric Boolean value should be treated as a number. You can do this by adding the double minus sign in front of a Boolean value or a cell reference, e. g. =A2=--TRUE or =A2=--B2.

The 1st minus sign, which is technically called the unary operator, coerces TRUE/FALSE to -1/0, respectively, and the second unary negates the values turning them into +1 and 0. This will probably be easier to understand looking at the following screenshot:
Comparing Boolean values and numbers

Note. You should add the double unary operator before a Boolean when using other logical operators such as not equal to, greater than or less than to correctly compare a numeric and Boolean values.

When using logical operators in complex formulas, you might also need to add the double unary before each logical expression that returns TRUE or FALSE as the result. Here's an example of such a formula: SUMPRODUCT and SUMIFS in Excel.

Using "Not equal to" logical operator in Excel

You use Excel's Not equal to operator (<>) when you want to make sure that a cell's value is not equal to a specified value. The use of the Not equal to operator is very similar to the use of Equal to that we discussed a moment ago.

The results returned by the Not equal to operator are analogous to the results produced by the Excel NOT function that reverses the value of its argument. The following table provides a few formula examples.

Not equal to operator NOT function Description
=A1<>B1 =NOT(A1=B1) Returns TRUE if the values in cells A1 and B1 are not the same, FALSE otherwise.
=A1<>"oranges" =NOT(A1="oranges") Returns TRUE if cell A1 contains any value other than "oranges", FALSE if it contains "oranges" or "ORANGES" or "Oranges", etc.
=A1<>TRUE =NOT(A1=TRUE) Returns TRUE if cell A1 contains any value other than TRUE, FALSE otherwise.
=A1<>(B1/2) =NOT(A1=B1/2) Returns TRUE if a number in cell A1 is not equal to the quotient of the division of B1 by 2, FALSE otherwise.
=A1<>DATEVALUE("12/1/2014") =NOT(A1=DATEVALUE("12/1/2014")) Returns TRUE if A1 contains any value other than the date of 1-Dec-2014, regardless of the date format, FALSE otherwise.

Greater than, less than, greater than or equal to, less than or equal to

You use these logical operators in Excel to check how one number compares to another. Microsoft Excel provides 4 comparison operates whose names are self-explanatory:

  • Greater than (>)
  • Greater than or equal to (>=)
  • Less than (<)
  • Less than or equal to (<=)

Most often, Excel comparison operators are used with numbers, date and time values. For example:

=A1>20 Returns TRUE if a number in cell A1 is greater than 20, FALSE otherwise.
=A1>=(B1/2) Returns TRUE if a number in cell A1 is greater than or equal to the quotient of the division of B1 by 2, FALSE otherwise.
=A1<DATEVALUE("12/1/2014") Returns TRUE if a date in cell A1 is less than 1-Dec-2014, FALSE otherwise.
=A1<=SUM(B1:D1) Returns TRUE if a number in cell A1 is less than or equal to the sum of values in cells B1:D1, FALSE otherwise.

Using Excel comparison operators with text values

In theory, you can also use the greater than, greater than or equal to operators as well as their less than counterparts with text values. For example, if cell A1 contains "apples" and B1 contains "bananas", guess what the formula =A1>B1 will return? Congratulations to those who've staked on FALSE : )

When comparing text values, Microsoft Excel ignores their case and compares the values symbol by symbol, "a" being considered the lowest text value and "z" - the highest text value.

So, when comparing the values of "apples" (A1) and "bananas" (B1), Excel starts with their first letters "a" and "b", respectively, and since "b" is greater than "a", the formula =A1>B1 returns FALSE.

If the first letters are the same, then the 2nd letters are compared, if they happen to be identical too, then Excel gets to the 3rd, 4th letters and so on. For example, if A1 contained "apples" and B1 contained "agave", the formula =A1>B1 would return TRUE because "p" is greater than "g".
Using Excel comparison operators with text values

At first sight, the use of comparison operators with text values seems to have very little practical sense, but you never know what you might need in the future, so probably this knowledge will prove helpful to someone.

Common uses of logical operators in Excel

In real work, Excel logical operators are rarely used on their own. Agree, the Boolean values TRUE and FALSE they return, though very true (excuse the pun), are not very meaningful. To get more sensible results, you can use logical operators as part of Excel functions or conditional formatting rules, as demonstrated in the below examples.

1. Using logical operators in arguments of Excel functions

When it comes to logical operators, Excel is very permissive and allows using them in parameters of many functions. One of the most common uses is found in Excel IF function where the comparison operators can help to construct a logical test, and the IF formula will return an appropriate result depending on whether the test evaluates to TRUE or FALSE. For example:

=IF(A1>=B1, "OK", "Not OK")

This simple IF formula returns OK if a value in cell A1 is greater than or equal to a value in cell B1, "Not OK" otherwise.

And here's another example:

=IF(A1<>B1, SUM(A1:C1), "")

The formula compares the values in cells A1 and B1, and if A1 is not equal to B1, the sum of values in cells A1:C1 is returned, an empty string otherwise.

Excel logical operators are also widely used in special IF functions such as SUMIF, COUNTIF, AVERAGEIF and their plural counterparts that return a result based on a certain condition or multiple conditions.

You can find a wealth of formula examples in the following tutorials:

2. Using Excel logical operators in mathematical calculations

Of course, Excel functions are very powerful, but you don't always have to use them to achieve the desired result. For example, the results returned by the following two formulas are identical:

IF function: =IF(B2>C2, B2*10, B2*5)

Formula with logical operators: =(B2>C2)*(B2*10)+(B2<=C2)*(B2*5)
Using Excel logical operators in mathematical calculations

I guess the IF formula is easier to interpret, right? It tells Excel to multiply a value in cell B2 by 10 if B2 is greater than C2, otherwise the value in B1 is multiplied by 5.

Now, let's analyze what the 2nd formula with the greater than and less than or equal to logical operators does. It helps to know that in mathematical calculations Excel does equate the Boolean value TRUE to 1, and FALSE to 0. Keeping this in mind, let's see what each of the logical expressions actually returns.

If a value in cell B2 is greater than a value in C2, then the expression B2>C2 is TRUE, and consequently equal to 1. On the other hand, B2<=C2 is FALSE and equal to 0. So, given that B2>C2, our formula undergoes the following transformation:
Formula with logical operators

Since any number multiplied by zero gives zero, we can cast away the second part of the formula after the plus sign. And because any number multiplied by 1 is that number, our complex formula turns into a simple =B2*10 that returns the product of multiplying B2 by 10, which is exactly what the above IF formula does : )

Obviously, if a value in cell B2 is less than in C2, then the expression B2>C2 evaluates to FALSE (0) and B2<=C2 to TRUE (1), meaning that the reverse of the described above will occur.

3. Logical operators in Excel conditional formatting

Another common use of logical operators is found in Excel Conditional Formatting that lets you quickly highlight the most important information in a spreadsheet.

For example, the following simple rules highlight selected cells or entire rows in your worksheet depending on a value in column A:

Less than (orange): =A1<5

Greater than (green): =A1>20
Using logical operator in Excel conditional formatting

For the detailed-step-by-step instructions and rule examples, please see the following articles:

As you see, the use of logical operators in Excel is intuitive and easy. In the next article, we are going to learn the nuts and bolts of Excel logical functions that allow performing more than one comparison in a formula. Please stay tuned and thank you for reading!

1256 comments

  1. I have one problem please help me

    i have 2 value cell D6 value & E6
    if value D6 >= E6+(E6*0.5%) answer is E6
    if value D6 <=E6-(E6*0.5%) answer is E6
    if value D6 < E6-(E6*0.5%) answer is S6

    thanks & regards
    Niranjan

  2. I have the following formula and Excel continues to give me errors. Help, please!

    =IF(B126>20,"A",IF(AND(B126=0),"B",IF(AND(B126(-20)), "C"), IF(B126<(-20), "D")))

    • Hello, Matthew,

      first of all, you don't need to use AND function because you specify only one criterion after it. Then, you missed the logical operator in B126(-20): should B126 be equal to -20? Also, there's no need to use round brackets for negatives in this case.

      So, try this formula:
      =IF(B126>20,"A",IF(B126=0,"B",IF(B126=-20,"C",IF(B126<-20,"D")))) Please note that you didn't specify what to return when B126<0 but greater than -20; when B126=20 and when B126>0 but lower than 20. Logically the formula requires these criteria too.

      But I do hope that the formula above is what you were looking for :)

  3. Hi Svetlana,

    Scenario:
    F8 = 1
    D10 = 0
    E10 = 7

    I want to create an IF formula to ask if F8 is greater than D10 but less than E10, then return a value of 1. If not, then return a blank.

    I created the following:
    IF(F8>D10<=E10,1,"")

    but this returns a blank instead of 1. I am not sure why.

    I am sure it is probably quite simple, but can't seem to solve it - I would be grateful for your help.

    Many thanks!

  4. Hi,

    I have a problem if somebody can help me it would be very appreciable. I had wrote many formula but did not get results.

    We have data like:

    Age Actual Value Exempted Value
    50 30000
    50 14500
    50 25000
    60 30000
    60 19100
    60 35000

    We want to get results:
    Age Actual Value Exempted Value
    50 30000 25000
    50 14500 14500
    50 25000 25000
    60 30000 30000
    60 19100 19100
    60 35000 30000

    Note: There are upper cap for 25000 60

  5. Hi,

    Need help on this'

    1-24 = A
    25-30 = b
    31-48 = c

    This is my formula but not working
    =IF(A1=25,A1=31,"C")))

    many thanks,
    necie

  6. Hi Guys
    some one help me for fixing up this issue,
    formula for:-
    If the amount is less than 50,00,000 then its 0%, if the amount is between 50 lakhs and 1 cr its 10% and above 1 cr its 15%.

  7. Hi can someone help me in this.
    I need to add numbers between given two numbers
    Eg.
    if I give first number 18 and last number 20 in different cell
    the number should generate Automatically in this sequence
    18.25
    18.50
    18.75
    19.00
    19.25
    19.50
    19.75
    20.00
    the sequence should stop to given last number.
    please help me out
    thank you

  8. Hi,
    Can someone assist me with the following request please.

    In Column A1, if someone types or pull the following hours of data from the list (8,16,24,32,40,48,56,64,72). The max is 72 hours.

    Column B1 should provide the following:
    1. Remaining hours left

    Column C1 should provide the following:
    1. Percentage of hours left from 100%
    2. Color scales of stop light (Green, Yellow, Red)

    I hope that I was able to make a sense of my request! Thank you in advance!

  9. I am seeking assistance on a formula: If C3-B3 is greater than 51% then E14 is C3-B3*.10

    If 100-35 > 51, then 65*.10

    Thank you in advance!

  10. Hello,
    I'm trying to setup a formula within the conditional formatting. If i have two cells that have the same name in them, then I'm hoping to have the conditonal formatting kick in and shade the a cell a certain color. Where I get stuck is getting the formula to refer to the conditional formatting instead of giving me a text output as the result.

    For example, =IF(AND(A1=Bob,A2=Bob),X,X) Where X represents the instruction to shade or not shade a cell.

    I know I can put a formula in a conditional format rule but not sure how to make the true/false variables refer to the shading.

    Any advise/help would be appreciated!
    Thanks,
    Corey

  11. The formula is:
    IF((D3="Men"),(E11>19,E1115,E11<25),RED,NO FILL)

    Thanks for help provided.

    John

  12. i have a sheet with a drop down list of "Men" and "Women". i have put the following IF formula based on the criteria of BMR between the range for Men >19 but 15 but 19,E1115,E11<25),RED,BLUE)

    I am getting all wrong somewhere. Please rectify the same.

    Thanks in advance.

    John Sanil

  13. I have a question. I'm trying to work out a formula where, if a figure (A) is lower than a figure range it will equal YES. And if a figure (A) is greater than figure range it will equal NO

    Figure range
    1 to 12
    1 to 24
    1 to 36
    1 to 120
    1 to 240

    example: IF (A) is between 1 to 12 = YES, greater than 12 = NO

    I hope this makes some sort of sense and you can help.

  14. =IF(AND(G3>=$C$3,G3<=$D$3),"Pass","Fail")

    I want to be able to Round both the Less than or Equal to value and the Greater than or equal to value. I want to be able to Round the greater than or equal to value up and and the less than or equal to down. Every time I try and add rounding to the above formula I get errors.

    Example Nominal Low Tol. Upper Tol. Act. Act. Form.Above
    PD Go Top 0 deg. 27.735 27.735 27.747 27.7471 27.747 Fail

  15. Help! I trying to find if cell A1 is equal to B1 and if it is highlight it a secific color, red. There are about 15k so I'll need to drag the formula down. Please help!

    • Hello, Anna,

      if I understand your task correctly and you need to fill the cells with a colour depending on the result of the formula, then conditional formatting is what you need to take a look at.
      You create the following rule:
      =$A1=$B1
      and apply it to
      =$A:$B

      Hope this helps.

  16. Hi,

    I am trying to apply a formula that returns a Text answer to the greater or less than number difference compared to an adjacent cell.

    The purpose is for a 14 question questionnaire with either an A. or B. answer. The answer is determined by the criteria as follows:

    "To score your test, add the number of questions you answered A and the
    number you answered B"

    - If your number of A answers is 3 or more than B answers, you are a
    Protein Type.

    - If your number of A and B answers are tied or within 2 of each other, you
    are a Mixed Type.

    - If your number of B answers is 3 or more than A answers, you are a
    Carbohydrate Type.

    I would like to return the text either "Protein Type", "Carb Type", "Mixed Type" based on the A. and B. totals.

    Many Thanks

    • Hi Brad,

      Let's assume that your data is arranged in the following way:
      NestedIf

      A1:C15 is the table with questions (Qs) and answers (As).
      Using COUNTIF in F2 and G2 we can find out the number of 'A' and 'B' answers accordingly:

      =COUNTIF(C2:C15,"A") (for F2)
      =COUNTIF(C2:C15,"B") (for G2)

      Then, in F4 we need to use nested IF function to apply all the conditions you described:
      =IF((F2-G2)>=3, "Protein Type", IF(AND((F2-G2)<=2,(F2-G2)>=-2),"Mixed Type","Carb Type"))

      or a bit shorter version:
      =IF((F2-G2)>=3, "Protein Type", IF(ABS(F2-G2)<=2,"Mixed Type","Carb Type"))

      Try to adjust this example formulas to your data, and learn more on the used functions from the links above. Hope it helps!

  17. Hi
    I am trying to write a formula to colour code some values by looking at a formula. If the value is higher than the target it should print P, if it is equal to the target G and if it is within 90% of the target A and below 90% of target R. I have it working for some values but not for others.

    eg the target is 0.4 - students made 0.4 progress so it should go green but it is going Amber. The 0.4 is calculated from another formula. If I type 0.4 then it goes green. I'm not sure what is going wrong.

    Any help greatly appreciated.

    • Hi, Sarah,

      could you send us a workbook sample with the data you use and the result you expect to get to support@ablebits.com? If it's impossible, then open your 'Conditional Formatting Rules Manager' and make sure that Stop If True box is checked for every rule you created.

  18. Hello everyone
    Kindly help me out as today i was trying to find out some.i can explain you by an example

    Column A
    2.5
    2.8
    2.7
    2.44
    2.32
    1.8
    3.2

    I want to put them in two different column
    Column 1- Value upto 2.5 but if less than 2.5 then put the lower value means if we select 1.8 then result will b 1.8
    Column 2 - value which is greater then 2.5 but after deduction of 2.5 mean if we select 3.2 then the result will be 0.7

  19. Please HELP...

    im not so familiar using TRUE and FALSE, but i want to know more.

    example i have a constant value of 10,000.
    i want to know if [cell[A1] 5,000 ] is lesser than [cell[B1] 10,000, and [cell[B1] 10,000 is lesser than [cell[C1] 20,000.

    i made this formula, please correct me.
    = if(A1<B1<C1, "false","true")

    then, if i change the constant value [cell[B1] to be 1,000] the answer must be "FALSE".
    how to make this right? my answer always "TRUE" though i change the constant value at cell[B1] to a lesser value.

    i know this is wrong, but please correct me, what it should exactly be.

    THANKS..

    • You need to add AND function into your formula for multiple conditions. Try using the following:

      =IF(AND(A1<B1, B1<C1),"true","false")

      • Hi,

        I'm having the same problem, only I'm trying to determine a "True","False" outcome for numbers different by a specific amount. How do I write the above solution to include a specific difference. Eg: If A1 is different than B1 by 3 or more then "Text A", but B1 is different by 3 then "Text B". If they A1 and B1 are within a difference of 2 then "Text C".

        I have posted a comment below, but found it difficult to explain myself properly.

        Many Thanks

        • Hi Brad,

          If my understanding of the task is correct, the following formula should work a treat:

          =IF(A1-B1>=3,"text A",IF(B1-A1>=3,"text B","text C"))

  20. If a1 is 40 b1 should be 40 if a1 is 50 b1 should be 50 if a1 is 60 b1 should be 50 kinly send a formula

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)