Features of !SEMTools
↑ Навигация по задачам в Excel и возможностям надстройки !SEMTools ↑

SEARCH

SEARCH function examples table in Excel
SEARCH function in Excel - examples
Function categoryText
VolatilityNon-volatile
Similar functionsFIND, find and replace (procedure)

What does the SEARCH function do?

This function is similar to the FIND function and also searches for a substring within a string. When the search text is found, its position in the text is displayed as a number.

The difference from the FIND function is that SEARCH is case-insensitive. Both for the search text and the text being searched. It also supports wildcard operators.

Both functions have a procedure-analog Find and Replace - as a procedure, it has its own advantages and disadvantages.

SEARCH function syntax

=SEARCH(Find_Text, Within_Text, [Start_Position])
SEARCH: position, case, start, wildcards
C2=SEARCH("e",A2)
ABCD
1TextFormulaResultComment
2Excel and excel=SEARCH("e",A2)1=SEARCH("e",A2)case-insensitive: E at position 1
3Excel and excel=FIND("e",A3)4=FIND("e",A3)FIND is case-sensitive
4Excel and excel=SEARCH("e",A4,5)9=SEARCH("e",A4,5)search from position 5
5Excel and excel=SEARCH("x?e",A5)2=SEARCH("x?e",A5)wildcards: ? is one character
6Excel and excel=SEARCH("z",A6)#VALUE!=SEARCH("z",A6)not found

“Excel”: E is 1, x is 2, c is 3, e is 4. SEARCH ignores case, so it finds the capital E at once; FIND looks for the lowercase e and returns 4. “x?e” matches “xce” starting at position 2.

  • Find_Text — character or combination being searched for
  • Within_Text — cell, text value, or any expression returned by another function
  • Start_Position — optional parameter, if omitted search starts from the first character

If the text contains more than one occurrence, the position of the first one is returned.
The third (optional) parameter is used to search from a specific position in the text and defaults to 1.

If the search text is not found in the text, the function returns a #VALUE! error.

SEARCH: result and input format

When searching for dates, the SEARCH function, like all text functions, treats them as numbers, so for correct searching the TEXT function may be needed.

Meanwhile, logical values TRUE and FALSE are converted to text corresponding to their spelling.

Search for a character in a cell

The simplest example of using the function is searching for a specific character in a cell.

The logic is simple - if searching for the character's position doesn't return an error, then the character is present in the cell:

=NOT(ISERROR(SEARCH(pattern, text)))
Does the cell contain a character
B2=NOT(ISERROR(SEARCH("@",A2)))
AB
1TextHas “@”?
2info@semtools.guruTRUE=NOT(ISERROR(SEARCH("@",A2)))
3no email hereFALSE=NOT(ISERROR(SEARCH("@",A3)))

A position means the character is there, an error means it isn’t. A shorter version: =ISNUMBER(SEARCH("@",A2)).

Search for character in cell - example table
Search for character in cell using SEARCH formula

Extract the first word with SEARCH

In this simplest example, we extract the first word from a cell using the combination — LEFT function + SEARCH function. Since space is a case-insensitive character, for this case you could also use the FIND function.

SEARCH function in formula extracting text before space
Determine position of first space and return characters up to that position

The table above was used to extract the first name from a string containing first and last name.

=LEFT(A1,SEARCH(" ",A1)-1)
The first word: LEFT + SEARCH
B2=LEFT(A2,SEARCH(" ",A2)-1)
AB
1Full nameFirst name
2John SmithJohn=LEFT(A2,SEARCH(" ",A2)-1)
3Anna Maria BrownAnna=LEFT(A3,SEARCH(" ",A3)-1)
4Max#VALUE!=LEFT(A4,SEARCH(" ",A4)-1)

SEARCH finds the first space, and LEFT takes everything before it. A single word without spaces returns #VALUE!; =IFERROR(LEFT(A4,SEARCH(" ",A4)-1),A4) returns the word itself.

  1. SEARCH returns the position of the space between first and last name
  2. The length of the first name is calculated as the space position minus 1
  3. LEFT function extracts the first name based on its length

More SEARCH formula examples

Find the first digit in a cell:

=MIN(IFERROR(SEARCH({0,9,8,7,6,5,4,3,2,1}, A1), 1000))

Find the first digit in a cell and return everything before it:

=LEFT(A1, MIN(IFERROR(SEARCH({0,9,8,7,6,5,4,3,2,1}, A1), 1000)) - 1)
Position of the first digit and the text before it
B2=MIN(IFERROR(SEARCH({0,9,8,7,6,5,4,3,2,1},A2),1000))
ABC
1TextFirst digit atBefore the digit
2Room 12B6=MIN(IFERROR(SEARCH({0,9,8,7,6,5,4,3,2,1},A2),1000))Room =LEFT(A2,MIN(IFERROR(SEARCH({0,9,8,7,6,5,4,3,2,1},A2),1000))-1)
3Order#45127=MIN(IFERROR(SEARCH({0,9,8,7,6,5,4,3,2,1},A3),1000))Order#=LEFT(A3,MIN(IFERROR(SEARCH({0,9,8,7,6,5,4,3,2,1},A3),1000))-1)
4No digits1000=MIN(IFERROR(SEARCH({0,9,8,7,6,5,4,3,2,1},A4),1000))No digits=LEFT(A4,MIN(IFERROR(SEARCH({0,9,8,7,6,5,4,3,2,1},A4),1000))-1)

SEARCH looks for each of the 10 digits; IFERROR turns “not found” into 1000, and MIN picks the smallest position. Without digits the position is 1000 and LEFT returns the whole text. Excel 2019 and earlier: Ctrl+Shift+Enter.

Check if a cell contains Latin characters. The formula returns "TRUE" or "FALSE":

=COUNT(SEARCH({"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}, A1)) > 0

SEARCH function in array formula

The examples above, where letters are explicitly listed in a string array, take up quite a lot of space. The letters go in sequence, which suggests they could be expressed as a range differently.

And indeed, this is possible using a combination with ROW and SEARCH functions:

{=COUNT(SEARCH(CHAR(ROW(65:90)), A1)) > 0}

The difference between this array formula and the previous ones is that it needs to be entered without curly braces, they will appear when entering the formula with Ctrl + Shift + Enter (instead of regular Enter). In the formula above where all letters are explicitly listed, curly braces are entered manually - this is an explicit indication of a string array.

What happens in this formula?

  • The ROW function with numerical argument "65:90" returns an array of numbers from 65 to 90 inclusive. Exactly in this range in the ASCII table are all Latin characters;
  • CHAR function returns for each numerical value in this array its character, thus creating an array of Latin characters;
  • The SEARCH function searches for each of these characters in the string and returns either a number or an error, thus creating an array of numbers and errors
  • The COUNT function counts numerical values in the resulting array. If the result is greater than zero, then at least one Latin character was found. If not (all searches returned an error), then none were found

Similar formula for Cyrillic:

{=COUNT(SEARCH(UNICHAR(ROW(1040:1071)),A1))>0}
Latin or Cyrillic letters in a cell
D2=COUNT(SEARCH(UNICHAR(ROW(1040:1071)),A2))>0
ABCD
1TextLatin letters?CHAR(65:90)Cyrillic?
2МоскваFALSE=COUNT(SEARCH({"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"},A2))>0FALSE=COUNT(SEARCH(CHAR(ROW(65:90)),A2))>0TRUE=COUNT(SEARCH(UNICHAR(ROW(1040:1071)),A2))>0
3iPhone 15TRUE=COUNT(SEARCH({"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"},A3))>0TRUE=COUNT(SEARCH(CHAR(ROW(65:90)),A3))>0FALSE=COUNT(SEARCH(UNICHAR(ROW(1040:1071)),A3))>0
412345FALSE=COUNT(SEARCH({"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"},A4))>0FALSE=COUNT(SEARCH(CHAR(ROW(65:90)),A4))>0FALSE=COUNT(SEARCH(UNICHAR(ROW(1040:1071)),A4))>0
5Привет, worldTRUE=COUNT(SEARCH({"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"},A5))>0TRUE=COUNT(SEARCH(CHAR(ROW(65:90)),A5))>0TRUE=COUNT(SEARCH(UNICHAR(ROW(1040:1071)),A5))>0

The list of 26 letters and CHAR(ROW(65:90)) give the same result: SEARCH ignores case, so the capital A–Z codes find lowercase letters too. For Cyrillic the article used CHAR(192:223) — that only works on Russian Windows; on other systems those codes are accented Latin letters. UNICHAR(1040…1071) covers А–Я on any system (Excel 2013+).

Read more about finding and extracting Cyrillic and Latin characters in Excel here:

Find Latin characters in text

There are many more combinations of the SEARCH function with other Excel functions, see sections:
OR function
AND function
VALUE function
Remove first word in Excel cell


See also on this topic:

Finding tools (!SEMTools add-in functionality)

Regular expressions in Excel

Find specific characters in Excel

Find words in cells

Find numbers in text cells

Like the article? Help its author! Buy !SEMTools, it has lots of useful instruments to process text data.