Comparison Operators
Part of the Fundamentals section of Coddy's Excel journey. Lesson 36 of 42.
The condition inside an IF is built from a comparison operator. There are six, and together they can ask any yes/no question about numbers:
> greater than
< less than
>= greater than or equal (at least)
<= less than or equal (at most)
= equal to
<> not equal toThe odd one out is <>, Excel's way of saying not equal. =IF(B2<>B1,"different","equal") shows different whenever the two cells don't match.
A curious fact: you can type a comparison as a formula all by itself, like =B2>B1. It shows TRUE when the comparison holds and FALSE when it doesn't, a raw yes/no called a logical value. It's a neat trick for peeking at a condition, but a sheet full of TRUE and FALSE doesn't say what each answer means. Wrapping the comparison in an IF turns that raw answer into words anyone can read.
Choosing between the close cousins matters: > versus >= only disagree when the two sides are exactly equal, and that's precisely where off-by-one bugs live. When you write a condition, always ask yourself: what should happen at the boundary?
Challenge
EasyA small sales sheet: A1 says Target with the target in B1, and A2 says Sales with this month's sales in B2.
Write three IF formulas, each using a different comparison operator:
- In
C1: showhitif sales are at least the target, otherwisemissed - In
C2: showunderif sales are below the target, otherwisenot under - In
C3: showdifferentif sales and target are not equal, otherwiseequal
Use the exact lowercase words above. The tests will try sales above, below and exactly equal to the target.
Try it yourself
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Target | 100 | |||||
| 2 | Sales | 130 | |||||
| 3 | |||||||
| 4 | |||||||
| 5 | |||||||
| 6 | |||||||
| 7 | |||||||
| 8 | |||||||
| 9 | |||||||
| 10 | |||||||
| 11 | |||||||
| 12 | |||||||
| 13 | |||||||
| 14 |
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
1Meet the Spreadsheet
What Is a Spreadsheet?Cells and ReferencesYour First CellsRows, Columns and the GridRecap: Meet the Grid4Cell References
Referencing Other CellsFormulas That UpdateChained FormulasRanges from A1 to A10Recap: Cell References7Decisions with IF
The IF FunctionWriting an IFComparison OperatorsNested IFsRecap: Decisions with IFPractice on your own: Excel playground