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. Hi great explanations on your page! I wonder if you could help me?
    I'm trying to calculate shipping costs for our dog food order. I have a delivery weight column ex. 5kg-12kg and a price column ex. £6.50 (C5) along with an order with column ex. 6.2 (A5) Using an IF formula i want for the whole range upto 200kg
    I've entered =IF(A5>=512<=24,C6) etc etc
    However it tells me that I can't compare a boolean to a number because they are different types, I tried entering the double unary you suggested "--" but without success. Can you tell me what I'm doing wrong?
    Many Thanks, appreciate your time :)

  2. Hi

    Need some help with this one: i have two columsn and want to use A1=B1 and should give answer TRUE as it is the same field but getting FALSE?

    • Hi Adri,

      If the values in A1 and B1 are absolutely identical, your formula will return TRUE.

      If it returns FALSE, then the values are different, though they may look the same. For example, these may be decimal numbers with 1 or 2 decimal places displayed, and these places are identical, while the 4th or 5th place is different.

      There can be a lot of other differences not noticeable at the first sight. Regrettably, it's impossible to spot the exact reason without seeing your data.

  3. Hi,

    Need a little help with a logical if condition if you have time.

    I have three groups of ranges each with 3 questions, and they can have a value of high, medium or low i.e.
    range 1 - H / H / M
    range 2 - H / M / M
    range 3 - H / L / L

    If all of the values in range 1 = high, and the values in range 2 and 3 = high or medium, then return high
    If any of the values in range 1 = high or medium, and 2 or more in range 2 and 3 = high or medium, then return medium
    If any of the values in range 1 = low, and 2 or more in range 2 and 3 = low, then return low

    Thanks for any help possible.

  4. I am trying to build a formula that takes data from one sheet and transfers it to another sheet in the spreadsheet if the value in the column indicated on the first sheet equals "Yes". Please help.

    • I'm also trying to figure this out. I would imagine it would be an If equals sort of thing, but I'm not sure how to do it.

      • You can use the VLOOKUP function to pull matching data from another worksheet and the IF function to check if the condition is met.

        For example, the following formula checks if the value in B2 is "yes", and if it is, it pulls the data for "Product1" from column C on Sheet1; otherwise it returns an empty string:

        =IF(B2="yes", VLOOKUP("Product1", Sheet1!A2:C10, 3, FALSE), "")

        Instead of "Product1", you can refer to the cell containing your key value, say A2:

        =IF(B2="yes", VLOOKUP(A2, Sheet1!A2:C10, 3, FALSE), "")

  5. Hello, Need some one help to apply logical if condition. There is data in column i want to apply if condition....

    A2 B2 Result should be like
    5 (1550)
    6 (1900)
    4 (1200)
    8 (2600)
    If A2 is less than equal to "4" multiple by 300. OR if its greater than equal to "4" multiple by 350.

    • Hi Mohd,

      You can use the following IF function:

      =IF(A2<=4, A2*300, A2*350)

      • Thanks!

  6. I have part numbers in a column, some contain the letter V at the end and some do not. I want a formula that indicates the part numbers that contain the V to simply display the value in another cell, and the ones without a V to calculate a simple multiplication.

    Thanks
    Vic

  7. A CPA associate answered my question: =IF((ISTEXT(B8)=TRUE),0,B8)*IF((ISTEXT(D8)=TRUE),0,D8)
    easy peasy thank you for your concern.

  8. I have a simple formula B8*D8, there are times when I want to include various text messages in the cells B8 or D8 and I want the formula to ignore the text and not create an error message. I have tried IF(B8=XXXXX,0,B8)*IF(D8=XXXXX,0,D8) where I have put the x's I have tried everything I can think of to describe any text with no success.

    • Hi Jeff,

      The following formula returns an empty string if an error occurs, otherwise the product of B8 and D8:
      =IFERROR(B8*D8, "")

      Is this what you are looking for?

  9. Hi! I tried to use this formula but the result is wrong, or it marks the formula as inconsistent... How can I change this to work?
    =COUNTIF(C3:C42,">6<12")

    • Hi Fany,

      Since you have 2 criteria, you should use the COUNTIFS function and define each condition separately:

      =COUNTIFS(C3:C42, ">6", C3:C42, "<12")

  10. Sorry the above arguments is not complete. Here's the complete one.

    1. If C3>=(10),then 10 days and above behind schedule
    2. If C3=B3, then on schudule

  11. Hi I'm trying to monitor the days of the delivery date if it is on schedule or behind schedule. Can anyone help me please, below are the arguments. Thanks!

    1. If C3>=(10),then 10 days and above behind schedule
    2. If C3=B3, then on schudule

    • Hi Mushy,

      Here you go:

      =IF(C3=B3, "on schedule", IF(C3>=10, "behind schedule", ""))

  12. Hi There,

    I am working on a report where I have to compare three columns to match a Tier 1-5 based on dollar value in a second column and a risk rating in a third.

    i.e Col c is Tier, Col f is Risk (High, medium, low, blank), col H is total cost $value. I need to be able to filter out errors where if it says tier 2, it could have any risk rating but must fall in to threshold of $10MM to $49,999,999.99 OR if it is rated "high" risk and falls between threshold of $1MM to $9,999,999.99.

    I need to show times when there is improper matching of tier and dollar value and highlight those records.

    Any formula suggestions would be helpful!
    Thanks!

  13. Hi,
    I am trying to prepare aging report in one column there are amounts related to different years. For example
    1- 12-Jan-2013 8,000
    2- 12-jan-2014 9,000
    3- 12-jan-2015 10,000

    so I want amount related to 2013 in One column, for 2014 in next means each year in different column.

  14. I'm trying to get a formula to do the following.
    If B3 matches any cell exactly in a list say K3 through K30 then multiply G3 by .0223. I would like to have a few criteria ranges but if I can get help with the first one, I should be able to replicate it for the other criteria.

    • Hi Michael,

      Try the following array formula (remember to press Ctrl+Shift+Enter):

      =IF(SUM(--(B3=K3:K30))>=1, G3*0.0223, "")

  15. Hi,

    How can fix this formula. Pls revert. thanks in advance

    Value is 31
    Week 1- (Normal Hrs*Rate+OT@Rate)Value is 1>=7, Ruselt will be colomn 1
    Week 2- (Normal Hrs*Rate+OT@Rate)value is 1>=14,Ruselt will be colomn 2
    Week 3- (Normal Hrs*Rate+OT@Rate)Value is 1>=21,Ruselt will be colomn 3
    Week 4- (Normal Hrs*Rate+OT@Rate)Value is 1>=28,Ruselt will be colomn 4

  16. Hi there,
    I am trying to make a formula based on the cell number falling within a certain range. The problem is: if the number is between 1 and 120 I need it to multiply that number by 11.2. If the number is between 120 and 200 I need to it multiply the number by 10. If the number is between 200 and 280 then I need that number multiplied by 8.5. If the number is between 280 and 450 I need the number multiplied by 7.2, and if the number is over 450 then it needs to be multiplied by 6.6. The number is created by the data I add in other cells. I have tried nested IF's, but the formula only seems to stay true if the number is over 450, The others don't add up to what they should. Can someone please help?
    thanks,
    Cheryl-Ann

    • Hi Cheryl-Ann,

      The following formula seems to work just fine:

      =IF(A1>450, A1*6.6, IF(A1>=280, A1*7.2, IF(A2>=200, A1*8.5, IF(A1>=120, A1*10, IF(AND(A1>1, A1<120), A1*11.2, "")))))

  17. thank you

  18. I am trying to create a formula using if statement that takes 2 values and devides them. If the result is greater than 100 I want it to put 100 in the field, if the result is less than 100 I want it to put the result of the division. this is what I have and it is not working

    =IF(D3/C3>100, 100, D3/C3)

    Can somebody help me with the correct formula.

    thanks

    • Hi Kevin,

      The formula is correct. However, if C3 is blank or contains a zero, it returns #DIV/0 error because you cannot divide by 0. Is this the case?

      As a workaround, you can wrap your formula in the IFERROR function, like this:

      =IFERROR(IF(D3/C3>100, 100, D3/C3), "")

      If C3 is 0 or blank, it returns an empty string. Or you can type any message within "".

  19. It will be appreciated if you could assist with a formula I already have.

    I am already using formula:

    =IF(A17>25000,(270+((((ROUNDUP(A17,-3))-25000)/1000)*6)),IF(1000.0125000,(30+((((ROUNDUP(A17,-3))-1000)/1000)*10)),30))

    My questions is: What I am missing when the value is zero the fee should be zero, but I am getting $20

    Based on contract price:

    A. Up to and including the first $1,000.00 of contract price or fraction thereof, the fee shall be $30.00.

    Thereafter:
    B. Add $10.00 per each additional $1,000.00 up to $25,000.00 of contract price or fraction thereof. $30 +($24(k) x $10) = $270.00
    Thereafter:
    C. Add $6.00 per each additional $1,000.00 after and over the initial $25,000.00 of contract price or fraction thereof.

    $30 + (24(k) x 10) = $270.00 + $6.00 for each additional $1,000 after $25,001 and over.

  20. Trying to do conditional formatting on a column for if column K2 is greater than J2 highlight K2. The problem is that the values in the K column are all less than values (example <0.0045) so it highlights all of them regardless of the value. Is there any way to do a conditional formatting formula that will understand the values in the K column?

    • Hi Tad,

      Try creating a rule for column K with the following formula:

      =$K2>$J2 Where 2 is your first row with data.

      Make sure the rule does not apply to the header row, otherwise the formatting will get shifted 1 cell up.

      • I have a worksheet where I am trying to do if I4<J4 (an each subsequent row) then highlight, but I've tried:
        1) highlight the cells in column I, not including any header rows
        2) conditionally format rule "=$I4<$J4" (and then choose my formatting)
        3) it says applies to "$I$1:$I2413"
        However, it is not highlighting correctly (some cells where II are highlighted)

        • Hi Alison,

          You should write the formula for the top-most row of the range to which you want to apply the rule.

          For example, if you want the rule to be applied to $I$1:$I2413, then the right formula is =$I1<$J1 If you want to highlight values beginning with row 4, then make sure the rule based on your formula (=$I4<$J4) applies to $I$4:$I2413.

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 :)