Skip to content
xlsoffice. All Rights Reserved
  • Home
  • Excel For Beginners
  • Excel Intermediate
  • Advanced Excel For Experts

Lookup and Reference Examples

  • Last row number in range
  • CHOOSE function: Description, Usage, Syntax, Examples and Explanation
  • Lookup entire row in Excel
  • Basic INDEX MATCH approximate in Excel
  • How to get address of named range in Excel

Data Analysis Examples

  • Data Series in Excel
  • How to Sort by Color in Excel
  • Calculate Conditional Percentile ‘IF’ in table in Excel
  • Number and Text Filters Examples in Excel
  • How to add Trendline to a chart in Excel

Data Validation Examples

  • Excel Data validation no punctuation
  • Excel Data validation must begin with
  • Excel Data validation whole percentage only
  • Excel Data validation allow weekday only
  • Excel Data validation only dates between

How to check if cell contains some words but not others in Excel

by

To test a cell to see if contains certain words but not others, you can use an array formula based on the COUNT and SEARCH functions, wrapped in the AND function.

Formula

{=AND(COUNT(SEARCH(inc,A1))>0,COUNT(SEARCH(exc,A1))=0)}

Explanation

In the example shown, the formula in C5 is:

{=AND(COUNT(SEARCH(inc,B5))>0,COUNT(SEARCH(exc,B5))=0)}

This formula returns TRUE when B5 contains any of the words in the named range inc and none of the words in the named range exc.

This is an array formula and must be entered with Control + Shift + Enter.

Worked Example:   If this AND that OR that in Excel

How this formula works

This formula relies on the AND function to test two conditions at the same time:

  1. Count of words from named range inc is >0
  2. Count of words from named range exc is =0

If both conditions are TRUE, the formula returns TRUE. If either condition is FALSE, the formula returns FALSE.

The test for multiple words is done using the SEARCH function with help from COUNT.

Worked Example:   AND function: Description, Usage, Syntax, Examples and Explanation

When SEARCH receives more than one item to look for, it returns an array of results, one per item. When a match is found, SEARCH returns the position of the match. When no match is found, SEARCH returns the #VALUE error. The COUNT function gets a count of numbers in the array returned by SEARCH. COUNT ignores errors by default.

In the example shown, the formula is solved in steps like this

=AND(COUNT({1;11;#VALUE!})>0,COUNT({#VALUE!;#VALUE!})=0)
=AND(2>0,0=0)
=AND(TRUE,TRUE)
=TRUE

With hard-coded values

There’s no requirement that you use a range for your list of things. If you’re only looking for a small number of things, you can use a list in array format, which is called an array constant. For example, to test for red, blue, or green, but exclude pink and orange, you can use:

=AND(COUNT(SEARCH({"red","blue","green"},B5))>0,COUNT(SEARCH({"orange","pink"},B5))=0)

This version does not require the control + shift + enter array formula syntax.

Worked Example:   If this AND that in Excel

Post navigation

Previous Post:

How to check cell that contains one of many with exclusions in Excel

Next Post:

How to check cell that contains specific text in Excel

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learn Basic Excel

Ribbon
Workbook
Worksheets
Format Cells
Find & Select
Sort & Filter
Templates
Print
Share
Protect
Keyboard Shortcuts

Categories

  • Charts
  • Data Analysis
  • Data Validation
  • Excel Functions
    • Cube Functions
    • Database Functions
    • Date and Time Functions
    • Engineering Functions
    • Financial Functions
    • Information Functions
    • Logical Functions
    • Lookup and Reference Functions
    • Math and Trig Functions
    • Statistical Functions
    • Text Functions
    • Web Functions
  • Excel VBA
  • Excel Video Tutorials
  • Formatting
  • Grouping
  • Others
  • Extract word that begins with specific character in Excel
  • How to Remove Leading Spaces in Excel
  • How to split text string at specific character in Excel
  • BAHTTEXT function: Description, Usage, Syntax, Examples and Explanation
  • Extract middle name from full name — Manipulating NAMES in Excel
  • How to calculate next anniversary date or birthday in Excel
  • Calculate total hours that fall between two times in Excel
  • Get week number from date in Excel
  • Calculate days remaining in Excel
  • Calculate years between dates in Excel
  • How to calculate Net Present Value (NPV) in Excel
  • Calculate loan interest in given year in Excel
  • How to Calculate Tax Rates in Excel
  • ISPMT function: Description, Usage, Syntax, Examples and Explanation
  • COUPDAYSNC function: Description, Usage, Syntax, Examples and Explanation
Acronyms, Abbreviations, Initialism & What They Stand For
© 2021 xlsoffice. All Rights Reserved | Teal Smiles