AND and OR let one IF formula test several conditions. AND returns TRUE only when every condition is TRUE. OR returns TRUE when at least one condition is TRUE. You place AND or OR in the logical test, the first part of IF. If IF itself is new to you, start with how to use if function in excel.
AND: every condition must be true
Suppose a sales rep earns a bonus when they meet a sales target in B2 (10,000 or more) and have completed training, marked “Yes” in C2. In D2:
=IF(AND(B2>=10000, C2="Yes"), "Bonus", "No bonus")
If B2 is 12,000 and C2 is “Yes”, both tests are TRUE, so the result is “Bonus”. If C2 is “No”, the AND test is FALSE, and the result is “No bonus”, even though the sales target was met.
OR: any one condition is enough
Now suppose a store gives free shipping to members (B2 is “Yes”) and to any order over 100 (C2). The formula is:
=IF(OR(B2="Yes", C2>100), "Free shipping", "Standard shipping")
A member with a small order qualifies because one condition is TRUE. A non-member with an order of 150 also qualifies. Only a non-member with an order of 100 or less gets standard shipping.
Combining AND and OR
AND and OR can be nested. Excel evaluates the inner OR first, so it acts as one condition inside the AND. For example, free shipping might require membership, plus either a large order or a coupon:
=IF(AND(B2="Yes", OR(C2>100, D2="Coupon")), "Free shipping", "Standard shipping")
Each function has its own parentheses. Count them as you type, because a missing one changes which conditions belong together.
A common mistake: AND and OR are functions
A frequent error is writing a range test the way you would say it in words:
=IF(A2>=10 AND A2<=20, "Yes", "No")
Excel doesn’t accept AND placed between two comparisons, and it shows an error message instead of a result. AND and OR are functions, so the conditions go inside their parentheses, separated by commas:
=IF(AND(A2>=10, A2<=20), "Yes", "No")
The same applies to OR.
Watch for blank cells
A blank cell can pass some tests in ways you might not expect. For example, C2="Yes" is FALSE for a blank cell, but C2<>"Yes" is TRUE. If a blank should count as no answer, decide how the formula handles it before you copy it down. A dedicated check for blanks is covered in if cell is blank formula in excel.
When COUNTIFS or SUMIFS is simpler
If the goal is a count or a total for rows that meet conditions, rather than a label on each row, COUNTIFS or SUMIFS is usually simpler. For example, counting the rows where the region is North and sales are over 500 doesn’t need an IF on every row. See countifs with two conditions in excel and sumifs with multiple criteria in excel.