## How to use the SEARCH function

The SEARCH function returns a number representing the position of character at which a specific text string is found reading left to right. It is not a case-sensitive search.

The image above demonstrates the function in cell D3.

The first argument *find_text* is a cell reference to the value in cell C3, the function will look for the value specified in cell C3 in the value in cell B3.

It returns number 11 in this example. Text string "blue" is found in position 11 if you count characters from left to right "My car is blue".

Row 7 shows the text string with a single character in each cell, row 8 shows the count for each cell.

## Excel function syntax

SEARCH(*find_text*,*within_text*, [*start_num*])

## Arguments

find_text |
Required. Is the text you want to find. Wildcard characters (? and *) are allowed. |

within_text |
Required. Is the text in which you want to search for find_text. |

[start_num] |
Optional. Is the character number in within_text, counting from the left at which you want to start searching. If omitted 1 is used. |

## 1. Comments

The SEARCH function is not case sensitive, use the FIND function if lower and upper case letters are important.

The image above shows that using a text string in uppercase letters (cell C3) still matches the text in cell B3.

Formula in cell C3:

If the text string is not found the SEARCH function returns a #VALUE! error. The image above shows the erro output from the SEARCH function in cell C3.

Text string "red" is not found in cell B3 "brown horse", the issue with error values is that they break a formula, however, there are workarounds.

Use the ISNUMBER function to avoid breaking the formula. It returns TRUE if the returned value is a number and FALSE for everything else even errors.

Formula in cell C5:

ISNUMBER(SEARCH("red", B5))

becomes

ISNUMBER(SEARCH("red", "blue whale"))

becomes

ISNUMBER(#VALUE!)

and returns FALSE in cell C5.

## 2. Wildcard characters

There are two wildcard characters you can use in the SEARCH function.

Character |
Wildcard |
Description |

* | asterisk | Matches 0 (zero) to any number of characters. |

? | question mark | Matches one character only. |

Formula in cell D3:

The SEARCH function in cell D3 returns 1, cell C3 contains *blue. The asterisk matches any number of characters even 0 (zero).

*blue matches the entire text string in cell B3 "My car is blue" and therefore matches the first character and returns 1.

Formula in cell D4:

Cell C4 contains blue* and matches at the eleventh character, the asterisk matches any number of characters from zero and up.

Formula in cell D5:

The question mark character matches any single character, ?blue matches "My car is blue" at the tenth character. The ? matches the blank (space) as well and the SEARCH function returns 10.

Formula in cell D6:

blue? doesn't match text "My car is blue" and returns #VALUE! error. The question mark matches any single character but string "My car is blue" has no character after blue.

## 3. Count how many times a specific string is found in a cell using the SEARCH function?

You can't use the SEARCH function to count how many time a specific string exists in a cell, it will only return the number of the character of the string that first matches, reading from left to right.

This article explains how to Count specific text string in a cell.

## 4. Can you count how many times a specific string is found in a cell range using the SEARCH function?

Yes, but only one instance per cell. Formula in cell D3:

If you are an Excel 365 subscriber you can use the regular formula above. Excel users with previous versions can use the formula below.

Let me explain how these two formula work.

SEARCH(C3,B3:B5)

becomes

SEARCH("aa", {"aa bb cc aa dd"; "bb cc dd"; "aa bb cc aa dd"})

and returns {1; #VALUE!; 1}. The numbers indicate that a matching string is found.

ISNUMBER(SEARCH(C3,B3:B5))

becomes

ISNUMBER({1; #VALUE!; 1})

and returns {TRUE; FALSE; TRUE}. The SUM and SUMPRODUCT functions can't sum add boolean values, to convert boolean values to numbers simply multiply with 1.

ISNUMBER(SEARCH(C3,B3:B5))*1

becomes

{TRUE; FALSE; TRUE}*1

and returns {1;0;1}. 1 is the equivalent of boolean value TRUE and 0 (zero) is boolean value FALSE.

## 5. SEARCH function with multiple search values?

You can use multiple text strings, however, if there are more than one instance of a specific string only one is counted.

For example cell B3 contains two "aa" but the formula in cell D3 counts only one instance.

The formula returns 2 because text strings "aa" and "bb" are found in cell B3. The formula is exactly the same as the one above so I won't explain it again, however, note that the cell references are different.

## 6. How to get the position of the second instance?

The string "aa" we are looking for exists twice in cell B3, the following formula returns a number representing the position of the character of the string the second time it occurs.

This formula changes the first instance to another string so that the SEARCH function then finds the position of the second instance of the string we are looking for.

SEARCH(C3,B3) finds the position of the first instance, it returns 1. The REPLACE function then changes the first string to something else, in this case, character "|". If your cell contains this character already then I recommend changing it to something that is not used in the cell so the formula doesn't get confused.

REPLACE(B3,SEARCH(C3,B3),LEN(C3),REPT("|", LEN(C3)))

becomes

REPLACE(B3,SEARCH(C3,B3),LEN(C3),REPT("|", LEN("aa")))

becomes

REPLACE(B3,SEARCH(C3,B3),LEN(C3),REPT("|", 2))

becomes

REPLACE(B3,SEARCH(C3,B3),LEN(C3),"||")

becomes

REPLACE(B3,SEARCH(C3,B3),2,"||")

becomes

REPLACE(B3,1,2,"||")

becomes

REPLACE("aa bb cc aa dd",1,2,"||")

and returns "|| bb cc aa dd".

SEARCH(C3,REPLACE(B3,SEARCH(C3,B3),LEN(C3),REPT("|", LEN(C3))))

becomes

SEARCH(C3,"|| bb cc aa dd")

and returns 10 in cell D3.

## 7. How to get the relative position of all instances?

The following formula works only in Excel 365, it returns numbers representing the position of the found instances in a cell.

Dynamic array formula in cell C3:

### 7.1 Explaining formula in cell C3

#### Step 1 - Calculate the number of characters in a given cell

LEN(B3)

#### Step 2 - Create a sequence from 1 to n

SEQUENCE(LEN(B3))

#### Step 3 - Create an array of substrings

MID(B3, SEQUENCE(LEN(B3)), LEN(E3))

#### Step 4 - Compare substrings to condition

MID(B3, SEQUENCE(LEN(B3)), LEN(E3))=E3

#### Step 5 - Filter corresponding numbers

FILTER(SEQUENCE(LEN(B3)), MID(B3, SEQUENCE(LEN(B3)), LEN(E3))=E3)

#### Step 6 - Concatenate strings

TEXTJOIN(", ", TRUE, FILTER(SEQUENCE(LEN(B3)), MID(B3, SEQUENCE(LEN(B3)), LEN(E3))=E3))

### 'SEARCH' function examples

The following 36 articles contain the SEARCH function.

This post explains how to lookup a value and return multiple values. No array formula required.

The array formula in cell F3 counts cells in column B that contains at least one of the values in […]

The formula in cell C3 grabs the first word in B3 using a blank as the delimiting character. =LEFT(B3,SEARCH(" ",B3)-1) […]

Table of Contents Extract the last word Extract the last letter Extract the last number Get Excel *.xlsx file 1. […]

The formula in cell B10 extracts unique distinct values from cell range B2:d4 that contains the string specified in cell […]

The image above demonstrates a formula in cell F3 that extracts unique distinct values from column B if they contain […]

The array formula in cell B10 extracts duplicate values from cell range B2:D4 if they contain string specified in cell […]

Murlidhar asks: How do I search text in cell and use a date range to filter records? i.e st.Dt D1 […]

Table of contents Filter unique distinct row records Filter unique distinct row records but not blanks Filter unique distinct row […]

Question: How do I create a unique distinct list where adjacent cell values contain a search string? AA102 CA AA103 […]

This article demonstrates formulas that return the last value in a given cell range or column. The image above shows […]

This formula returns multiple values even if they are arranged differently or have minor misspellings compared to the lookup value.

The picture above shows you how to highlight rows containing text strings using conditional formatting. Example, continents criterion (cell B3) […]

Question: How to extract email addresses from this sheet? Answer: It depends on how the emails are populated in your worksheet? […]

This article describes a formula that returns all rows containing at least one digit 0 (zero) to 9. What's on […]

Question: How do i create a flexible search formula to search a list? Answer: The following formula let´s you search […]

This article demonstrates formulas that perform a partial match for a given cell using multiple strings specified in cells F2 […]

This article demonstrates different formulas based on if a cell contains a given text. Formula in cell C3: =B3=$E$3 The […]

This article demonstrates formulas that let you perform lookups using two or more conditions. The image above shows two conditions […]

This article demonstrates how to find a value in a column and concatenate corresponding values on the same row. The […]

This article demonstrates formulas that match two conditions in a column each and return another value on the same row […]

This article demonstrates array formulas that search for cell values containing a search string and returns corresponding values on the […]

Question: I want to search two columns with two search strings? The strings can be anywhere in these two columns […]

This article demonstrates formulas that let you perform partial matches based on multiple strings and return those strings if all […]

This article demonstrates a formula that searches a cell (partial match) based on values in a table and returns a […]

This article demonstrates a formula that extracts a row or record from a data table using two strings as criteria. […]

Question: Can expand this equation set into more than two colums of data, say if I had a first, middle […]

Mr.Excel had a "challenge of the month" June/July 2008 about Wildcard VLOOKUP: "The data in column A contains a series […]

Jerome asks, in this blog post Search for multiple text strings in multiple cells in excel : If the list […]

RU asks: Can you please suggest if i want to find out the rows with fixed value in "First Name" […]

This article demonstrates a formula that filters unique distinct single digits from a cell range containing numbers. Cell range B3:B6 […]

This article demonstrates formulas and a UDF that searches for values in a table based on concatenated values and returns […]

Question: I want to sum cells that have a "C" and a decimal number. The cells have other numbers and […]

This blog article describes how to split strings in a cell with space as a delimiting character, like Text to […]

This article demonstrates three different ways to filter a data set if a value contains a specific string and if […]

What's on this page Reverse text Insert random characters Convert letters to numbers How to shuffle characters in the alphabet […]

## Functions in this article

### Functions in 'Text' category

The SEARCH function function is one of many functions in the 'Text' category.

### Excel function categories

## Excel categories

### 3 Responses to “How to use the SEARCH function”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

Just an additon..

"The function works the same as the search function except case-sensitive" & Find doesn't works with wildcard characters — the question mark (?) and asterisk (*) where SEARCH can.. :)

Regards,

Deb

Thank you, Deb!

[…] SEARCH(find_text,within_text, [start_num]) Returns the number of the character at which a specific character or text string is first found, reading left to right (not case sensitive) […]