AND, OR and NOT
About this lesson
AND returns TRUE only when every test inside it is TRUE. OR returns TRUE when any one is. NOT reverses a test. So a rule with several conditions can sit inside a single IF.
- combine conditions with AND and OR inside an IF.
- flip a test with NOT and say when it is clearer than rewriting it.
The idea
Three small functions that turn several questions into one. AND is strict: every test must pass. OR is relaxed: any test will do. NOT reverses whatever it is given. Each returns TRUE or FALSE, so each can be the test of an IF. IF(AND(…), …) is how most real rules are written.
The mistake is writing a rule in words as "age over 18 or 21" and typing it as B2>18 OR 21. Every test inside AND or OR is a complete comparison of its own. It has its own cell and its own sign.
The mistake to watch for
Writing AND where the rule says either. AND is TRUE only when every test passes. OR is TRUE when any one does. A rule with two ways in needs OR. A rule that requires both needs AND. Say the rule out loud with the word and or the word or before you type the function.
Read more about this
Where this comes up again
This lesson needs JavaScript to run. Everything below is the lesson in full, but you cannot type into the grid or be marked.
AND returns TRUE only when every test inside it is TRUE.
In E2, type:
=AND(B2>=B7,D2>=B8)
An apprenticeship needs enough age and enough hours.
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | Applicant | Age | Portfolio | Hours worked | |||
| 2 | Sana K | 19 | Yes | 220 | |||
| 3 | Owen T | 17 | Yes | 340 | |||
| 4 | Ruth M | 24 | No | 410 | |||
| 5 | Femi A | 21 | Yes | 95 | |||
| 6 | |||||||
| 7 | Minimum age | 18 | |||||
| 8 | Minimum hours | 200 |
Every step
-
ANDreturnsTRUEonly when every test inside it isTRUE. InE2, type:=AND(B2>=B7,D2>=B8). An apprenticeship needs enough age and enough hours. -
Read
=AND(B5>=B7,D5>=B8)and say what it returns. Femi is 21 with 95 hours. -
ORreturnsTRUEwhen any one test isTRUE. InF4, ask whether Ruth's portfolio or hours qualify her. Shape:=OR(test, test). A portfolio counts as a second way in. -
NOTflipsTRUEtoFALSEandFALSEtoTRUE. InF3, wrap the age test inNOTfor Owen. Shape:=NOT(test). Anyone under 18 needs a guardian's signature. -
In
F2, combineIFandANDfor Sana's result. Shape:=IF(AND(test, test, test), if_true, if_false). Show Interview if all three pass, Reject otherwise.