Sub topic 2
Comparing values: =, <>, >, <, >=, <=
This chapter covers the six comparison operators that make up the test in an IF formula. It assumes you can enter data in cells, refer to cells such as B2, and use basic arithmetic operators like + and *. You do not need to know IF yet. The chapter ends with a few formulas that use IF to show the operators at work.
What a comparison does
A comparison looks at two values and answers one question: is the relationship true or not? The answer is always a Boolean, a value that is either TRUE or FALSE. A Boolean is not text and not a number. It is its own data type.
You can type a comparison into any cell to see the result:
=B2>=50If B2 holds 72, the cell shows TRUE. If it holds 31, the cell shows FALSE. IF takes this TRUE or FALSE and uses it to choose between two results. If you can write a correct comparison, you have written the hard part of an IF formula.
The six operators
| Operator | Meaning | Example | Result when A1 is 10 |
|---|---|---|---|
| `=` | equal to | `=A1=10` | `TRUE` |
| `<>` | not equal to | `=A1<>10` | `FALSE` |
| `>` | greater than | `=A1>5` | `TRUE` |
| `<` | less than | `=A1<5` | `FALSE` |
| `>=` | greater than or equal to | `=A1>=10` | `TRUE` |
| `<=` | less than or equal to | `=A1<=9` | `FALSE` |
The first = in each example starts the formula. Any = after that is the equality operator. So =A1=10 reads as "start a formula; is A1 equal to 10?" The two roles share one symbol, which confuses many beginners.
Google Sheets also provides function forms of these operators: EQ, NE, GT, GTE, LT, and LTE. For example, =GTE(A1, 10) gives the same result as =A1>=10. Each takes exactly two arguments and none do more than the operator, so most people use the operators.
Operators that do not exist
Several spellings from other languages do not work in Sheets:
!=is not valid. Use<>for "not equal".==is not valid. Use a single=.=>and=<are not valid. The=always comes second:>=and<=.
Sheets usually reports a formula parse error for these, which is easy to spot. A reversed >= typed as => is the most common cause.
Comparing numbers
Number comparisons work the way you expect. A few details matter in real sheets.
Percentages are numbers. A cell showing 50% holds 0.5. These two tests give the same answer for that cell:
=C2>0.5=C2>50%Dates are numbers too. Sheets stores a date as a count of days. Compare a date cell against a date built with the DATE function, not against typed text:
=D2<DATE(2026,12,31)This returns TRUE for any date before 31 December 2026. Typing "2026-12-31" in quotes creates text instead. That text may or may not be read as a date depending on your locale, so avoid it.
Stored-as-text numbers fail quietly. A value imported from a CSV file or pasted from a web page may look like a number but be text. A text "72" is not equal to the number 72. Signs of this problem are a left-aligned value in a number column, or a comparison that returns FALSE when it should return TRUE. You can test a cell with =ISNUMBER(B2). To convert, use VALUE(B2) or multiply the cell by 1.
Rounded displays can mislead. A cell formatted to show 2 decimals may hold 1.996. The comparison =B2>=2 uses the stored value, so it is FALSE even though the cell displays 2.00. When this matters, compare against a rounded value:
=ROUND(B2, 2)>=2Comparing text
Text values go inside double quotes in a comparison:
=A2="Paid"Without the quotes, Sheets reads Paid as the name of a function or a named range. It then returns an error such as #NAME?.
Equality ignores case
The = and <> operators are not case-sensitive. If A2 holds paid, PAID, or Paid, the test =A2="Paid" is TRUE. For a case-sensitive test, use EXACT:
=EXACT(A2, "Paid")EXACT returns TRUE only when the capitalization matches too.
Spaces count
"Paid " with a trailing space is a different string from "Paid". Data typed by hand or imported from other systems often has invisible extra spaces. If a comparison fails and the values look identical, trim the cell first:
=TRIM(A2)="Paid"No wildcards with =
The = operator compares the whole string exactly. =A2="Pa*" does not match "Paid". The asterisk is read as a literal character. Wildcard matching exists in functions like COUNTIF and SUMIF, but not in the = operator. To test whether a cell contains some text, use a function such as REGEXMATCH or SEARCH. Those come up later in the tutorial series.
Ordering text with > and <
You can use > and < on text. Sheets compares alphabetically and ignores case:
="apple"<"banana"This returns TRUE. Alphabetical ordering is rarely needed in IF formulas, but it explains an odd result you may see. If you compare a text cell with a number using > or <, Sheets does not raise an error. It gives a result based on its internal ordering of data types, and that result is rarely useful. If a comparison between a number and text seems to give a strange answer, check the cell types first.
Comparing a cell to another cell
The right side of a comparison does not have to be a typed value. It can be another cell:
=B2>=F1Here F1 might hold the pass mark. Changing F1 changes every formula that refers to it. This avoids "magic numbers" hidden inside formulas. When you copy such a formula down a column, you need an absolute reference such as $F$1. The next chapters cover that. For now, notice that a comparison works with any two values, whether typed or taken from a cell.
You can also compare the results of calculations:
=B2*1.2>C2Sheets evaluates the arithmetic first, then the comparison. Arithmetic operators have higher precedence than comparison operators, so no extra parentheses are needed. You can still add them for readability: =(B2*1.2)>C2.
Blank cells in comparisons
A blank cell behaves differently from what many learners expect. In a comparison, an empty cell acts as both an empty string and the number 0, depending on what it is compared to:
| Test (A1 is empty) | Result |
|---|---|
| `=A1=""` | `TRUE` |
| `=A1=0` | `TRUE` |
| `=A1>=50` | `FALSE` |
| `=A1<50` | `TRUE` |
| `=A1<>""` | `FALSE` |
The last two matter most. The test =A1<50 is TRUE for an empty cell, because the blank counts as 0. If you grade a column with "fail if below 50", every empty row is marked as a fail. The fix is to test for blanks first. Chapter 6 covers this in full. The test =A1="" is the standard blank check.
How Sheets evaluates a comparison
The flow below shows what happens when Sheets sees a formula such as =B2>=50 as the test inside IF.
Using comparisons inside IF
The full syntax of IF is the topic of the next chapter. A short preview shows how the comparison fits:
=IF(B2>=50, "Pass", "Fail")The comparison B2>=50 is the first argument. The other two arguments are the results for TRUE and FALSE. Here are two more examples, one for text and one for "not equal":
=IF(A2="Paid", "Done", "Follow up")=IF(A2<>"Paid", "Follow up", "Done")These two formulas give the same results. The second one inverts the test and swaps the outcomes. Neither is better. Choose the phrasing that matches how you think about the rule.
Choosing the right operator at the boundary
The most common comparison bug is an off-by-one error at the boundary value. Suppose the rule says "50 or above passes". These two tests differ for a score of exactly 50:
B2>50isFALSEat 50, so the student fails.B2>=50isTRUEat 50, so the student passes.
Before you write a formula, test the rule against the exact boundary. Ask: what should happen at 50? Then pick > or >= to match. Do the same for < and <=.
The same care applies to ranges such as "at least 10 and under 20". The lower bound uses >= and the upper bound uses <, so the value 20 belongs to the next range and no value falls in two ranges.
Common comparison mistakes
- Missing quotes around text.
=A2=Paidreturns an error. Write=A2="Paid". - Quotes around numbers.
=B2>="50"compares against text"50". Leave the quotes off. - A single
=in the wrong place. After the leading=, one=means equality. Do not write=IF(B2=>50, ...). - Extra spaces in data.
"Paid "does not equal"Paid". UseTRIM. - Numbers stored as text. Check with
ISNUMBER. - Assuming case matters. It does not for
=. UseEXACTif it must. - Blank cells treated as 0. Test with
=A2=""before comparing numbers.
Exercise
Column B holds scores. A teacher's rule says "a score of exactly 60 or more is a merit". A colleague wrote =B2>60 and a student with 60 was not marked as merit. Write the corrected comparison, and say what B2<>60 would return for that student.
Show answer
The corrected comparison is =B2>=60, because >= includes the boundary value 60. For a score of 60, =B2<>60 returns FALSE, since the score is equal to 60.
Exercise
Cell A2 contains the text "shipped". What do =A2="Shipped", =EXACT(A2,"Shipped"), and =A2="Ship*" return?
Show answer
=A2="Shipped" returns TRUE because the = operator ignores case. =EXACT(A2,"Shipped") returns FALSE because EXACT is case-sensitive and the capital S differs. =A2="Ship*" returns FALSE because = does not support wildcards, so the asterisk is read as a literal character.
Exercise
Cell C2 is empty. What do =C2="" and =C2<50 return, and why does the second result matter when you grade a column of scores?
Show answer
=C2="" returns TRUE and =C2<50 also returns TRUE. An empty cell counts as 0 in a numeric comparison, so any blank row would be treated as below 50 and marked as a fail. You should test for a blank cell first, for example with IF(C2="", "", ...).