Contains substring in excel

This is an old question but a solution for those using Excel 2016 or newer is you can remove the need for nested if structures by using the new IFS( condition1, return1 [,condition2, return2] ...) conditional.

I have formatted it to make it visually clearer on how to use it for the case of this question:

=IFS(
ISERROR(SEARCH("String1",A1))=FALSE,"Something1",
ISERROR(SEARCH("String2",A1))=FALSE,"Something2",
ISERROR(SEARCH("String3",A1))=FALSE,"Something3"
)

Since SEARCH returns an error if a string is not found I wrapped it with an ISERROR(...)=FALSE to check for truth and then return the value wanted. It would be great if SEARCH returned 0 instead of an error for readability, but thats just how it works unfortunately.

Another note of importance is that IFS will return the match that it finds first and thus ordering is important. For example if my strings were Surf, Surfing, Surfs as String1,String2,String3 above and my cells string was Surfing it would match on the first term instead of the second because of the substring being Surf. Thus common denominators need to be last in the list. My IFS would need to be ordered Surfing, Surfs, Surf to work correctly (swapping Surfing and Surfs would also work in this simple example), but Surf would need to be last.

In this example, the goal is to test a value in a cell to see if it contains a specific substring. Excel contains two functions designed to check the occurrence of one text string inside another: the SEARCH function and the FIND function. Both functions return the position of the substring if found as a number, and a #VALUE! error if the substring is not found. The difference is that the SEARCH function supports wildcards but is not case-sensitive, while the FIND function is case-sensitive but does not support wildcards. The general approach with either function is to use the ISNUMBER function to check for a numeric result (a match) and return TRUE or FALSE.

SEARCH function (not case-sensitive)

The SEARCH function is designed to look inside a text string for a specific substring. If SEARCH finds the substring, it returns a position of the substring in the text as a number. If the substring is not found, SEARCH returns a #VALUE error. For example:

=SEARCH("p","apple") // returns 2
=SEARCH("z","apple") // returns #VALUE!

To force a TRUE or FALSE result, we use the ISNUMBER function. ISNUMBER returns TRUE for numeric values and FALSE for anything else. So, if SEARCH finds the substring, it returns the position as a number, and ISNUMBER returns TRUE:

=ISNUMBER(SEARCH("p","apple")) // returns TRUE
=ISNUMBER(SEARCH("z","apple")) // returns FALSE

If SEARCH doesn’t find the substring, it returns an error, which causes the ISNUMBER to return FALSE.

Wildcards

Although SEARCH is not case-sensitive, it does support wildcards (*?~). For example, the question mark (?) wildcard matches any one character. The formula below looks for a 3-character substring beginning with «x» and ending in «y»:

=ISNUMBER(SEARCH("x?z","xyz")) // TRUE
=ISNUMBER(SEARCH("x?z","xbz")) // TRUE
=ISNUMBER(SEARCH("x?z","xyy")) // FALSE

The asterisk (*) wildcard matches zero or more characters. This wildcard is not as useful in the SEARCH function because SEARCH already looks for a substring. For example, it might seem like the following formula will test for a value that ends with «z»:

=ISNUMBER(SEARCH("*z",text))

However, because SEARCH automatically looks for a substring, the following formulas all return 1 as a result, even though the text in the first formula is the only text that ends with «z»:

=SEARCH("*z","XYZ") // returns 1
=SEARCH("*z","XYZXY") // returns 1
=SEARCH("*z","XYZXY123") // returns 1
=SEARCH("x*z","XYZXY123") // returns 1

This means the asterisk (*) is not a reliable way to test for «ends with». However, you an use the the asterisk (*) wildcard like this: 

=SEARCH("x*2*b","AAAXYZ123ABCZZZ") // returns 4
=SEARCH("x*2*b","NXYZ12563JKLB") // returns 2

Here we are looking for «x», «2», and «b» in that order, with any number of characters in between. Finally, you can use the tilde (~) as an escape character to indicate that the next character is a literal like this:

=SEARCH("~*","apple*") // returns 6
=SEARCH("~?","apple?") // returns 6
=SEARCH("~~","apple~") // returns 6

The above formulas use SEARCH to find a literal asterisk (*), question mark (?) , and tilde (~) in that order.

FIND function (case-sensitive)

Like the SEARCH function, the FIND function returns the position of a substring in text as a number, and an error if the substring is not found. However, unlike the SEARCH function, the FIND function respects case:

=FIND("A","Apple") // returns 1
=FIND("A","apple") // returns #VALUE!

To make a case-sensitive version of the formula, just replace the SEARCH function with the FIND function in the formula above:

=ISNUMBER(FIND(substring,A1))

The result is a case-sensitive search:

=ISNUMBER(FIND("A","Apple")) // returns TRUE
=ISNUMBER(FIND("A","apple")) // returns FALSE

If cell contains

To return a custom result when a cell contains specific text, add the IF function like this:

=IF(ISNUMBER(SEARCH(substring,A1)), "Yes", "No")

Instead of returning TRUE or FALSE, the formula above will return «Yes» if substring is found and «No» if not.

With hardcoded search string

To test for a hardcoded substring, enclose the text in double quotes («»). For example, to check A1 for the text «apple» use:

=ISNUMBER(SEARCH("apple",A1))

More than one search string

To test a cell for more than one thing (i.e. for one of many substrings), see this example formula.

To check if a cell contains specific text, use ISNUMBER and SEARCH in Excel. There’s no CONTAINS function in Excel.

1. To find the position of a substring in a text string, use the SEARCH function.

Search Function in Excel

Explanation: «duck» found at position 10, «donkey» found at position 1, cell A4 does not contain the word «horse» and «goat» found at position 12.

2. Add the ISNUMBER function. The ISNUMBER function returns TRUE if a cell contains a number, and FALSE if not.

IsNumber Function

Explanation: cell A2 contains the word «duck», cell A3 contains the word «donkey», cell A4 does not contain the word «horse» and cell A5 contains the word «goat».

3. You can also check if a cell contains specific text, without displaying the substring. Make sure to enclose the substring in double quotation marks.

Double Quotation Marks

4. To perform a case-sensitive search, replace the SEARCH function with the FIND function.

Case-sensitive Search

Explanation: the formula in cell C3 returns FALSE now. Cell A3 does not contain the word «donkey» but contains the word «Donkey».

5. Add the IF function. The formula below (case-insensitive) returns «Found» if a cell contains specific text, and «Not Found» if not.

Check If a Cell Contains Specific Text

6. You can also use IF and COUNTIF in Excel to check if a cell contains specific text. However, the COUNTIF function is always case-insensitive.

If and Countif Function

Explanation: the formula in cell C2 reduces to =IF(COUNTIF(A2,»*duck*»),»Found»,»Not Found»). An asterisk (*) matches a series of zero or more characters. Visit our page about the COUNTIF function to learn all you need to know about this powerful function.

In this article, we will learn how to search a substring from a given string in Excel.

In excel, substring is a part of another string. It can be a single character or a whole paragraph. To search a string for a specific substring, we will use the ISNUMBER function along with the FIND function in Excel. Instead of FIND, you can always use the excel SEARCH function for non-case sensitive searches.

ISNUMBER function is used to check the cell if it contains a number or not.

Syntax of ISNUMBER:   

The FIND function returns the position of the character in a text string, reading left to right (case-sensitive).

Syntax of Find:

=FIND(find_text,within_text,[start_num])

pasted image 0 (34)

Here we have two columns. Substring in Column B and Given string in Column A.

Write the formula in C2 cell

Formula:

Explanation:

Find function takes the substring from the B2 cell of Column B and it then matches it with the given string in the A2 cell of Column A.

ISNUMBER checks if the string matches, it returns True else it returns False.
pasted image 0 (35)

Copy the formula in other cells, select the cells taking the first cell where the formula is already applied, use shortcut key Ctrl+ D.

As you can see the output in column C shows True and False representing whether substring is there or not.

Now, what if you want to do a non-case sensitive search in excel?

How to search in excel cells for non-case sensitive substrings?

It’s simple. Replace the find function with the excel SEARCH function in the formula above.  Since SEARCH is case-insensitive.

There are more articles on FIND and SEARCH function to find strings or value. Hope you learned how to find substring in a string from the article. You can perform these tasks in Excel 2016, 2013 and 2010. If you have any unresolved query, please do comment below in the comment box. We will help you.

Related Articles:

How to Search a certain text in Excel

How to Sum if cells contain specific text in Excel

How to Sum if cell contains text in other cell in Excel

How to Count Cells that contain specific text in Excel

How to Split Numbers and Text from String in Excel

How to Highlight cells that contain specific text in Excel

Popular Articles:

50 Excel Shortcut to Increase Your Productivity

How to use the VLOOKUP Function in Excel

How to use the COUNTIF function in Excel 2016

How to use the SUMIF Function in Excel

There’s no CONTAINS function in Excel.

  1. To find the position of a substring in a text string, use the SEARCH function.
  2. Add the ISNUMBER function.
  3. You can also check if a cell contains specific text, without displaying the substring.
  4. To perform a case-sensitive search, replace the SEARCH function with the FIND function.

Contents

  • 1 How do you write an if contains statement in Excel?
  • 2 How do I find if a cell contains text in Excel?
  • 3 How do I check if a string contains many text in Excel?
  • 4 How do you check if a column contains a value in Excel?
  • 5 What can an Excel formula contains?
  • 6 How do you handle if cell contains a word then put a text in another cell?
  • 7 Can you do an IF formula with Contains?
  • 8 Can you do a Vlookup with Contains?
  • 9 What can an Excel formula contains Class 7?
  • 10 How do I know if a cell contains a text list?
  • 11 How do you know if a cell contains multiple values?
  • 12 What is an Xlookup in Excel?
  • 13 How do I compare a cell value in a column in Excel?
  • 14 How do I calculate a value in Excel?
  • 15 How do I find values in Excel?
  • 16 How do I add one to a specific cell if a cell contains certain text in Excel?
  • 17 How do I return a value in another cell if a cell contains certain text in Excel VBA?
  • 18 How do you use nested IF?
  • 19 HOW DO YOU FIND A or B in Excel?
  • 20 How do I match part of text in Excel?

How do you write an if contains statement in Excel?

Using “if cell contains” formulas in Excel

  1. Select the output cell, and use the following formula: =IF(cell<>“”, value_to_return, “”).
  2. For our example, the cell we want to check is A2, and the return value will be No.
  3. Since the A2 cell isn’t blank, the formula will return “No” in the output cell.

How do I find if a cell contains text in Excel?

Cell contains specific text

  1. Generic formula. =ISNUMBER(SEARCH(substring,text))
  2. To check if a cell contains specific text, you can use the SEARCH function together with the ISNUMBER function.
  3. The SEARCH function returns the position of the search string when found, and the #VALUE!
  4. How to use formula criteria (50 examples)

How do I check if a string contains many text in Excel?

Check if a cell contains one of several values from a list with formulas

  1. =SUMPRODUCT(–ISNUMBER(SEARCH($D$2:$D$7,A2)))>0.
  2. =IF(SUMPRODUCT(–ISNUMBER(SEARCH($D$2:$D$6,A2))),”Yes”,”No”)
  3. =TEXTJOIN(“, “, TRUE, IF(COUNTIF(A2, “*”&$D$2:$D$7&”*”), $D$2:$D$7, “”))

How do you check if a column contains a value in Excel?

Check if a value exists in a column using Conditional Formatting

  1. Select the values in Invoice No. column.
  2. Go to Conditional Formatting > Highlight Cells Rules > Equal to.
  3. A dialog box appears. Insert the value that needs to be searched in column.
  4. Select Formatting Style from the next drop-down list, and press OK.

What can an Excel formula contains?

A formula can also contain any or all of the following: functions, references, operators, and constants.
The parts of an Excel formula

  • Functions: The PI() function returns the value of pi: 3.142…
  • References: A2 returns the value in cell A2.
  • Constants: Numbers or text values entered directly into a formula, such as 2.

How do you handle if cell contains a word then put a text in another cell?

If a cell contains a word then select or highlight
If you want to check if a cell contains a specific word and then select or highlight it, you can apply the Select Specific Cells feature of Kutools for Excel, which can quickly handle this job.

Can you do an IF formula with Contains?

You can use the Excel If function with Find function to return TRUE if a Cell A1 Contains Text Value. Below is the formula to return True based on the text value.

Can you do a Vlookup with Contains?

Contains type match
This will join an asterisk to both sides of the lookup value so that VLOOKUP will find the first match that contains the text typed into H4. Note: you must set exact match mode using FALSE or 0 (zero) for the last argument in VLOOKUP when using wildcards.

What can an Excel formula contains Class 7?

It can include cell addresses, numbers, arithmetic operators and parenthesis. Using it, we can perform simple as well as complex calculations.

How do I know if a cell contains a text list?

1. Check if the cell contains any value in the list

  1. Type formula in cell C3.
  2. Press and hold CTRL + SHIFT simultaneously.
  3. Press Enter once.
  4. Release all keys.

How do you know if a cell contains multiple values?

If you want to check a cell that if it contains one of several values in a range, you can use the SEARCH function to search find_text in a range inside a text string. Then we can use the LOOKUP function to get the last match values….

What is an Xlookup in Excel?

Use the XLOOKUP function to find things in a table or range by row.With XLOOKUP, you can look in one column for a search term, and return a result from the same row in another column, regardless of which side the return column is on.

How do I compare a cell value in a column in Excel?

Here are the steps to do this:

  1. Select the entire data set.
  2. Click the Home tab.
  3. In the Styles group, click on the ‘Conditional Formatting’ option.
  4. Hover the cursor on the Highlight Cell Rules option.
  5. Click on Duplicate Values.
  6. In the Duplicate Values dialog box, make sure ‘Duplicate’ is selected.
  7. Specify the formatting.

How do I calculate a value in Excel?

IF statement between two numbers

  1. =IF(AND(C6>=C8,C6<=C9),C11,C12)
  2. Step 1: Put the number you want to test in cell C6 (150).
  3. Step 2: Put the criteria in cells C8 and C9 (100 and 999).
  4. Step 3: Put the results if true or false in cells C11 and C12 (100 and 0).
  5. Step 4: Type the formula =IF(AND(C6>=C8,C6<=C9),C11,C12).

How do I find values in Excel?

To find a value in Excel, use the Find and Replace dialog box. You can access this dialog using the keyboard shortcut control-F, or, by using the Find and Select menu at the far right of the Home tab on the ribbon.

How do I add one to a specific cell if a cell contains certain text in Excel?

The following array formula can help you add 1 to a specified cell if a cell in a range contains certain text in Excel. Please do as follows. 1. Select a blank cell, enter formula =SUM(IF(A2:A7=”Judy”,1,0)) + Ctrl + Shift + Enter.

How do I return a value in another cell if a cell contains certain text in Excel VBA?

If Cell Contains Specific Text Then Return Value – Using SEARCH Function

  1. Parameter 1: B2=”find_text”, the text where you can replace with the specific text to be searched in another text.
  2. Parameter 2: A2=”within_text”, where you will search for ‘find_text’

How do you use nested IF?

We nest an IF function by setting value_if_false to IF B2 greater than or equal to 80, return B. We use additional nested IF functions to test for C, D, and F grades. I am copying the formula. In this formula, we must test B2 greater than or equal to 90 first, and then, B2 greater than or equal to 80, and so on.

HOW DO YOU FIND A or B in Excel?

1 Answer. press CTRL + SHIFT + ENTER to evaluate it.

How do I match part of text in Excel?

If you just want to find which name is partial match the given name, you also can use this formula =INDEX($E$2:$E$14,MATCH($K$1&”*”,E2:E14,0)). (E2:E14 is the column list you want to lookup from, k1 is the given name, you can change as you need.)

Like this post? Please share to your friends:
  • Contained in symbol word
  • Contact to excel apk
  • Construction word of the day
  • Construction of russian word
  • Constituent parts of the word