## Excel Formula: Check if cell contains some texts but not contains others

To check if a cell contains some texts in range A but does not contain the texts in range B, you can use an array formula which combines the COUNT, SEARCH and AND function in Excel. Here this tutorial explains how to use this array formula.

**Generic formula:**

=AND(COUNT(SEARCH(include,text))>0,COUNT(SEARCH(exclude,text))=0) |

**Arguments**

Text: the text string you want to check. |

Include: the values you want to check if argument text contains. |

Exclude: the values you want to check if argument text does not contain. |

**Return value:**

This formula returns logical value. If the cell contains at least one of argument Include but does not contain any one of argument Exclude, it will return TRUE, or it will return FALSE.

**How this formula work**

Supposing you want to check if the cell B3 contains one of values in range E3:E5, but at the same time, it does not contain anyone values in range F3:F4, please use below formula

=AND(COUNT(SEARCH($E$3:$E$5,B3))>0,COUNT(SEARCH($F$3:$F$4,B3))=0) |

Press **Shift + Ctrl + Enter** key to check the cell.

**Explanation**

**Part 1: ( COUNT(SEARCH($E$3:$E$5,B3))>0 check if cell B3 contains one of values in range E3:E5**

SEARCH function: the SEARCH function returns the position of the first character of the text string inside another, if the SEARCH function finds the matched text, it returns the relative position, if not, it returns #VALUE! error. Here, the formula *SEARCH($E$3:$E$5,B3)* will search each value in the range E3:E5 in cell B3, and return the location of each text string in the cell B3. It will return an array result as this: *{1;7;#VALUE!}*.

COUNT function: the COUNT function counts the number of items in a range or an array. *COUNT(SEARCH($E$3:$E$5,B3))* returns 2 as the number of items in the array *{1;7;#VALUE!}* is two.

*COUNT(SEARCH($E$3:$E$5,B3))>0*, compare the result of COUNT function and zero, as long as the result of COUNT function is greater than 0, the result will return TRUE, or it will return FALSE. Here it returns TRUE.

**Part 2: COUNT(SEARCH($F$3:$F$4,B3))=0 check if cell B3 does not contain one of values in range F3:F4**

SEARCH function: the SEARCH function returns the position of the first character of the text string inside another, if the SEARCH function finds the matched text, it returns the relative position; if not, it returns #VALUE! error. Here, the formula *SEARCH($F$3:$F$4,B3)* will search each value of the range F3:F4 in cell B3, and returns the location of each text string in the cell B3. It will return an array result as this: *{#VALUE!; #VALUE!;#VALUE!}*.

COUNT function: the COUNT function counts the number of items in a range or an array. *COUNT(SEARCH($F$3:$F$4,B3))* returns 0 as there are no items in the array *{#VALUE!; #VALUE!;#VALUE!}* .

*COUNT(SEARCH($F$3:$F$4,B3))>0*, compare the result of COUNT function and zero, as long as the result of COUNT function is equal to 0, it will return TRUE, or it will return FALSE. Here it returns TRUE.

**Part 3: AND function**

=AND(COUNT(SEARCH($E$3:$E$5,B3))>0,COUNT(SEARCH($F$3:$F$4,B3))=0)

=AND(TRUE,TRUE)

=TRUE

** Sample File**

#### Relative Formulas

- Check if a cell contains a specific text

To check if a cell contains some texts in range A but does not contain the texts in range B, you can use an array formula which combines the COUNT, SEARCH and AND function in Excel - Check if a cell contains one of several values but exclude other values

This tutorial will provide a formula to quickly handle the task that check if a cell contains one of things but excluding other values in Excel and explain the arguments of the formula. - Check if cell contains one of things

Supposing in Excel, there is a list of values in column E, you want to check if the cells in column B contain all of the values in column E, and return TRUE or FALSE. - Check if cell contains number

Sometimes, you may want to check if a cell contains numeric characters. This tutorial provides a formula which will return TRUE if the cell contains number, FALSE if cell does not contain number.

**The Best Office Productivity Tools**

#### Kutools for Excel - Helps You To Stand Out From Crowd

Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300 powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) and save 80% time for you.

- Designed for 1500 work scenarios, helps you solve 80% Excel problems.
- Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
- Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
- 30-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years.

#### Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

- One second to switch between dozens of open documents!
- Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
- Increases your productivity by 50% when viewing and editing multiple documents.
- Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Firefox, And New Internet Explorer.