How to If Not This Or That in Excel

Learn multiple Excel methods to if not this or that with step-by-step examples and practical applications.

excelformulaspreadsheettutorial
11 min read • Last updated: 7/2/2025

How to If Not This Or That in Excel

Why This Task Matters in Excel

Data‐driven decisions often depend on filtering out unwanted values. “If Not This Or That” is the shorthand many analysts use to describe the need to run a calculation or return a result only when a cell’s content is not equal to one value or another. Imagine customer‐service dashboards that should exclude the statuses “Pending” and “Deferred,” or financial models that should ignore the product codes “X” and “Y” when calculating commissions. In each of these cases the business logic is “do something unless the entry equals either of two specific items.”

In practice, this kind of logic powers business rules across industries:

  • Retail – Return “Reorder” unless the stock status equals “Backordered” or “Discontinued.”
  • Manufacturing – Trigger a maintenance alert unless the machine state equals “Offline” or “Under Inspection.”
  • Education – Flag students unless the grade equals “Pass” or “Exempt.”

Microsoft Excel is uniquely well suited for this task because it combines straightforward logical operators with a wide range of complementary functions. The classic combination is IF with either AND or NOT(OR()), though newer functions such as IFS, SWITCH, and dynamic arrays (like FILTER) can deliver the same outcome with alternative syntax or better performance on large data ranges.

Mastering the “If Not This Or That” pattern connects directly to core spreadsheet workflows: data validation, conditional formatting, automated reporting, error trapping, and dashboard logic. Neglecting the technique increases the risk of misclassifying records, generating inaccurate totals, or conveying incorrect insights to stakeholders. By understanding the underlying logic, analysts can expand the rule to cover three, four, or even dozens of exclusions and confidently chain it with other conditions—paving the way to more advanced skills, such as nested LET constructions or VBA automation.

Best Excel Approach

The most reliable way to implement “If Not This Or That” is to embed an AND test inside an IF statement:

=IF(AND(A2<>"Red",A2<>"Blue"),"Include","Exclude")

Why this works:
AND requires all logical tests to be TRUE. We flip each test from equality to inequality (using <> which means “not equal to”). For the overall AND to evaluate as TRUE, the value in A2 must be different from “Red” and different from “Blue.” Only then will the IF return the “Include” result.

Use this structure when:

  • You have a small, fixed list of disallowed items (typically two to five).
  • You need maximum backward compatibility—AND, <>, and IF exist in every Excel version since 1993.
  • You want the simplest mental model: “Only when both ‘not equal’ tests pass, proceed.”

Alternative syntax—wrapping NOT around an OR delivers the same truth table:

=IF(NOT(OR(A2="Red",A2="Blue")),"Include","Exclude")

Pick NOT(OR()) when you find it easier to think in positive language (“Is it any of the banned values?”) and then invert. Both formulas calculate at identical speed; the choice is readability.

Parameters and Inputs

  • Primary Input: A single cell or expression to test—text, numbers, dates, or logical values.
  • Exclusion List: Two or more explicit literals (e.g., \"Red\", \"Blue\") or cell references that hold the banned values.
  • Optional Output: The value or calculation to return when the test passes (e.g., \"Include\", numeric multiplier, blank cell \"\").
  • Alternative Output: The value to return when the test fails (e.g., \"Exclude\", zero, error message).

Preparation tips:

  1. Consistency—ensure text case matches or wrap tests in UPPER() or LOWER() when user entry is unpredictable.
  2. Trim whitespace—stray spaces cause equality tests to fail; preprocess with TRIM() if needed.
  3. Data Types—avoid comparing text with numbers: \"5\" is not equal to 5. Apply VALUE() or TEXT() conversions beforehand.
  4. Dynamic Exclusions—store banned items in a named range so updates flow automatically without editing the formula.
  5. Error Values—if inputs may be #N/A, wrap them in IFERROR() before logical evaluation.

Edge Cases: truly blank cells ("") versus genuine empty cells can behave differently under equality tests. Use LEN(A2)=0 when you must distinguish.

Step-by-Step Examples

Example 1: Basic Scenario

Suppose you run a small e-commerce site and want to mark orders that should be included in the “Quick Ship” queue. Orders should be excluded if the shipping method equals “Freight” or “Drop-Ship.”

Sample data:

  A            B
1 Order ID   Shipping Method
2 1001       Standard
3 1002       Freight
4 1003       Express
5 1004       Drop-Ship
6 1005       Standard

Step-by-Step:

  1. In cell C1 type “Quick Ship?” to label the new column.
  2. In C2 enter:
=IF(AND(B2<>"Freight",B2<>"Drop-Ship"),"Yes","No")
  1. Copy the formula down to C6. The results should read:
  • C2 → Yes (Standard qualifies)
  • C3 → No (Freight excluded)
  • C4 → Yes (Express qualifies)
  • C5 → No (Drop-Ship excluded)
  • C6 → Yes

Why it works: each row passes through two inequality tests. Only rows whose method differs from both “Freight” and “Drop-Ship” receive “Yes.”

Variations:

  • Return a blank when excluded: change \"No\" to \"\".
  • Use NOT(OR()) version for readability:
=IF(NOT(OR(B2="Freight",B2="Drop-Ship")),"Yes","")

Troubleshooting:

  • If “Freight ” (with a trailing space) sneaks into the data, it will incorrectly qualify. Use TRIM(B2) inside each comparison or pre-clean column B.

Example 2: Real-World Application

A human-resources analyst must calculate overtime pay, but only for employees whose status is not “Contractor” or “Intern.” The dataset spans thousands of rows and includes multiple departments.

Setup (first six rows):

 A          B           C       D
1 Emp ID   Status     Hours   Rate
2  E001    Full-Time  45      28
3  E002    Contractor 50      35
4  E003    Part-Time  41      22
5  E004    Intern     48      18
6  E005    Full-Time  37      30

Goal: Compute overtime pay in column E based on hours above 40, applying Rate × 1.5 multiplier, but only when Status is neither “Contractor” nor “Intern.”

Formula in E2:

=IF(AND(B2<>"Contractor",B2<>"Intern",C2>40),(C2-40)*D2*1.5,0)

Walkthrough:

  1. The first two conditions exclude disqualified statuses.
  2. The third condition C2 greater than 40 ensures overtime logic applies only when hours exceed the standard 40.
  3. If all three conditions are satisfied, overtime hours (C2-40) are multiplied by the employee’s rate and the 1.5 premium.
  4. Otherwise, the formula returns zero.

Copying the formula down yields:

  • E2 → (45-40) × 28 × 1.5 = 210
  • E3 → 0 (Contractor)
  • E4 → (41-40) × 22 × 1.5 = 33
  • E5 → 0 (Intern)
  • E6 → 0 (hours ≤ 40)

Integration: PivotTables can now sum the overtime column without manual filtering. Conditional formatting can highlight large overtime payouts, while a slicer on “Status” remains fully functional because the logic lives in the formula, not a filter.

Performance: Even on 50 000 rows the AND approach is efficient because it uses only direct comparisons and arithmetic—no array scans or volatile functions.

Example 3: Advanced Technique

Scenario: A supply-chain analyst must allocate inventory replenishment orders but skip items classified as either “Obsolete,” “End-of-Life,” or “On Hold.” The disallowed codes live in a maintenance table that can change weekly. The analyst also wants the formula to remain dynamic without editing cell formulas when new exclusions appear.

  1. Create a named range disallowed_codes pointing to the maintenance list [G2:G10] where codes such as “Obsolete,” “End-of-Life,” and “On Hold” reside.
  2. Main data (first four rows):
 A           B
1 SKU       Status
2 100-XL    On Hold
3 200-MD    Active
4 300-SM    End-of-Life
  1. In C1 type “Replenish?” and in C2 enter:
=IF(COUNTIF(disallowed_codes,B2)=0,"Yes","No")

Why this is advanced:

  • COUNTIF checks the cell B2 against the entire dynamic list. If the count equals zero, B2 is not in the disallowed list.
  • This scales to any number of exclusions without changing the formula.
  • Maintenance staff can add “Retired,” “Recalled,” or any future status to the list, and all downstream logic updates instantly.

Performance optimization:

  • COUNTIF is non-volatile and can handle tens of thousands of rows quickly.
  • Wrap in LET to calculate the boolean once and reuse if additional downstream logic is required. Example:
=LET(
  bad,COUNTIF(disallowed_codes,B2)=0,
  IF(bad,"Yes","No")
)

Error handling:

  • If the status cell may contain #N/A, nest the reference inside IFERROR(B2,"") inside the COUNTIF.

Professional tip:

  • Pair this dynamic exclusion with a structured table (Ctrl+T) so the named range expands automatically without intervention.

Tips and Best Practices

  1. Store exclusions in a dedicated sheet and convert to a table for dynamic range expansion—this avoids formula edits.
  2. Use descriptive named ranges like banned_status_list to enhance readability and auditing.
  3. When exclusions are short, AND or NOT(OR()) reads clearer than COUNTIF. Prioritize readability over brevity.
  4. Combine with conditional formatting to visually flag included or excluded rows—immediate QA feedback.
  5. Minimize volatile functions (INDIRECT, OFFSET) around the logic to preserve calculation speed on large models.
  6. Comment complex logic with N("text") or cell notes so future users know the business rule behind the exclusion list.

Common Mistakes to Avoid

  1. Accidentally testing for equality instead of inequality: writing A2="Red" instead of A2<>"Red" inside AND will invert the logic. Examine unexpected surges in “Yes” results as a tell-tale sign.
  2. Mixing data types—comparing numeric codes stored as text with real numbers causes false mismatches. Convert before comparing.
  3. Forgetting to handle blank cells—"" can slip through exclusion lists. Add an explicit LEN(A2)>0 test if empties should be excluded or included deliberately.
  4. Hard-coding exclusions—analysts often embed “Obsolete” and “On Hold” directly in ten formulas. The moment a new disallowed status arises, you must update every formula. Centralize your exclusions instead.
  5. Overusing array formulas—wrapping a simple two-value exclusion in MATCH with whole-column references can degrade performance. Choose the simplest function set that accomplishes the goal.

Alternative Methods

MethodSyntax CoreProsConsBest For
AND with <>IF(AND(A2<>"X",A2<>"Y"),…)Very clear, backward compatibleRe-edit formula when list growsSmall fixed exclusion list
NOT with ORIF(NOT(OR(A2="X",A2="Y")),…)Thought process “is it any of these?”Slightly harder to read nested NOTSame as above; preference choice
COUNTIF =0IF(COUNTIF(list,A2)=0,…)Scales to dynamic lists; easy maintenanceRequires separate exclusion rangeMedium to large, changeable list
ISNA MATCHIF(ISNA(MATCH(A2,list,0)),…)Supports case-sensitive MATCH, can return positionSlightly slower than COUNTIFCase-sensitive exclusions
XLOOKUPIF(ISNA(XLOOKUP(A2,list,list)),"Include","Exclude")Modern syntax, optional wildcard matchingExcel 365+ only365 users needing advanced matching
Power Query filterUI‐basedNo formulas to maintain; loads huge datasetsAdds refresh layer; learning curveETL pipelines, very large imports

Compatibility: COUNTIF works from Excel 2007 onward, whereas XLOOKUP requires Microsoft 365 or Excel 2021+. Choose based on target audience and deployment environment.

Migration strategy: Start with AND for pilot models. When exclusions exceed three, move the banned values to a table and switch to COUNTIF. Update documentation accordingly.

FAQ

When should I use this approach?

Use “If Not This Or That” whenever you must execute logic only when a value fails to match one or more disallowed items. It is ideal for filtering, conditional formatting, alert flags, and selective calculations where exclusions drive the decision.

Can this work across multiple sheets?

Absolutely. Point your exclusion list to another worksheet: COUNTIF(Sheet2!$A:$A,B2)=0. For many sheets, consolidate the exclusion lists into a single named range to avoid scattered logic.

What are the limitations?

AND and OR become unwieldy beyond five conditions. Also, equality tests are case‐insensitive for text unless you use EXACT, MATCH, or SEARCH. Finally, hard-coded exclusions require formula edits for new items.

How do I handle errors?

Wrap the input in IFERROR() or LET to substitute blanks for error values before the logical test. Example: =IF(AND(IFERROR(B2,"")<>"Red",IFERROR(B2,"")<>"Blue"),"OK","Check").

Does this work in older Excel versions?

Yes. IF, AND, OR, and COUNTIF exist in Excel 2003 and later. Dynamic arrays and XLOOKUP are limited to Microsoft 365 or Excel 2021+. Adapt your method to your users’ version.

What about performance with large datasets?

COUNTIF with a one‐dimensional range scales well to hundreds of thousands of rows. Avoid volatile functions, disable full column references where possible (use [A2:A50000] rather than [A:A]), and use structured tables to limit calculation scope.

Conclusion

Mastering “If Not This Or That” equips you to embed powerful exclusion logic into any spreadsheet. Whether you use AND, NOT(OR()), or dynamic list techniques like COUNTIF, you gain fine-grained control over data flows, ensuring only qualifying records affect your models and reports. By centralizing exclusion criteria, preparing clean inputs, and choosing the right function for scale, you unlock more robust dashboards and automate error-free decision rules. Continue experimenting with named ranges, structured tables, and modern functions like XLOOKUP to refine and extend this foundational skill across all your Excel projects.

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve.