AND, OR and NOT in Excel: combine conditions
AND needs every test to be TRUE, OR needs one, NOT turns a result round. How each works on its own, inside IF, and how to read a formula that mixes them.
AND returns TRUE only when every test inside it is TRUE. OR returns TRUE when at least one test is TRUE. NOT turns TRUE into FALSE and FALSE into TRUE.
All three work in every version of Excel. On their own they show TRUE or FALSE. Inside IF they let one cell follow a rule with several parts.
Here is a list of expense claims from a small office. The rules for paying them are the kind every finance team writes down. Type the table in A1 to D7. Leave C7 empty, because Omar sent no receipt and nobody typed anything.
| Row | A | B | C | D |
|---|---|---|---|---|
| 1 | Name | Amount | Receipt | Age (days) |
| 2 | Hana | 45 | Yes | 3 |
| 3 | Jonas | 120 | Yes | 10 |
| 4 | Leila | 80 | No | 2 |
| 5 | Marco | 640 | Yes | 5 |
| 6 | Nia | 100 | Yes | 40 |
| 7 | Omar | 30 | 35 |
Type each formula in F2 and fill it down to F7. The results below are listed from Hana down to Omar.
AND: every test must pass
The rule: a claim of 100 or less with a receipt can be paid at once.
=AND(B2<=100,C2="Yes") →
TRUE, FALSE, FALSE, FALSE, TRUE, FALSE
Jonas has a receipt but claims 120, so one test fails. Leila claims 80 but has no receipt. One FALSE anywhere makes the whole AND FALSE.
Nia claims exactly 100 and passes. That is because the sign is
<=. With < she would
fail. Read the rule again and decide which sign it means before you type.
Each test is a full comparison with its own cell. Commas go between the tests. AND can take up to 255 tests. More than 3 is hard for the next person to read.
OR: one test is enough
The rule: a manager looks at any claim over 500, or any claim older than 30 days.
=OR(B2>500,D2>30) →
FALSE, FALSE, FALSE, TRUE, TRUE, TRUE
Marco is over 500. Nia and Omar are late. Each of them passes one test, and one is enough. OR is FALSE only when every test is FALSE.
A good check is to say the rule out loud. If you hear "and", use AND. If you hear "or", use OR. People often write AND when the rule has two ways in.
NOT: turn a result round
The rule: find every claim without a receipt.
The first idea is =C2="No". It finds Leila. It misses Omar,
because his cell is empty, and an empty cell is not "No".
=NOT(C2="Yes") →
FALSE, FALSE, TRUE, FALSE, FALSE, TRUE
This asks a better question. Is there a Yes in the cell? If not, the claim has no receipt. That catches "No", an empty cell, and a typo like "Y".
=C2<>"Yes" gives the same answers. The sign
<> means "not equal to". Use whichever one your team
reads more easily. NOT is clearer when the test inside it is long.
One more thing about text. The equals sign ignores capitals, so
=C2="yes" is TRUE for Hana. Somebody typing "YES" does not
break the rule.
Inside IF: words instead of TRUE and FALSE
A column of TRUE and FALSE is fine for you. The person paying the claims wants a word. AND, OR and NOT each return TRUE or FALSE. So each one fits in the first part of IF.
=IF(AND(B2<=100,C2="Yes"),"Pay","Check") →
Pay, Check, Check, Check, Pay, Check
The shape is =IF(AND(test, test), if_true, if_false). The
AND is the test. IF only chooses which word to show.
Count the results with =COUNTIF(F2:F7,"Pay"). It gives 2.
Reading a formula that mixes them
Here is a rule from a real policy. Check any claim over 500. Also check a claim over 50 with no receipt. Pay the rest. Small claims without a receipt are fine.
=IF(OR(B2>500,AND(NOT(C2="Yes"),B2>50)),"Check","Pay")
→ Pay, Pay, Check, Check, Pay, Pay
This looks hard. It is not, if you read it from the inside out. Start with the deepest brackets and work outward.
-
NOT(C2="Yes")means "no receipt". -
AND(NOT(C2="Yes"),B2>50)means "no receipt and over 50". It is TRUE only for Leila. -
OR(B2>500, ...)means "over 500, or the part in step 2". It is TRUE for Leila and Marco. - IF shows Check when the OR is TRUE, and Pay when it is FALSE.
Omar has no receipt, but his claim is 30. So step 2 is FALSE for him and he is paid. Nia is late, but lateness is not part of this rule. The formula does exactly what the policy says.
When you build a formula like this, build it the same way. Type the inside part in its own cell first and fill it down. Check the TRUE and FALSE values. Then wrap the next function around it.
Mistakes that give no error
A number where a test should be
The rule says "over 500 or older than 30 days". Somebody types
=OR(B2>500,30). Every row shows TRUE.
The 30 is not a test. It is a number, and Excel treats any number that is not 0 as TRUE. So OR
always finds one TRUE. Write the full test: D2>30.
A test with a missing cell
=AND(B2>=50,<=100) is how people say "between 50 and
100". Excel does not accept it. Each test needs its own cell:
=AND(B2>=50,B2<=100).
A whole range inside AND
=AND(B2:B7<=100) gives one answer for the whole column. Here
it is FALSE, because Jonas and Marco claim more than 100. It does not give one answer per row.
Write the test for row 2 and fill it down.
For many rows at once, FILTER and SUMPRODUCT use * for "and"
and + for "or". The
FILTER function article shows how.
AND where the rule says or
=AND(B2>500,D2>30) looks for claims that are big and late
at the same time. There are none here, so every row is FALSE. A column that is all FALSE, or
all TRUE, is a sign to read the rule again.
For more IF practice, try the IF function exercises. When a rule has more than two outcomes, read how to replace a nested IF. Each lesson below is a real sheet you type into. Each answer is checked when you press Enter.