Use search in excel

SEARCH, SEARCHB functions

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel for Mac 2011 Excel Starter 2010 More…Less

This article describes the formula syntax and usage of the SEARCH and SEARCHB functions in Microsoft Excel.

Description

The SEARCH and SEARCHB functions locate one text string within a second text string, and return the number of the starting position of the first text string from the first character of the second text string. For example, to find the position of the letter «n» in the word «printer», you can use the following function:

=SEARCH(«n»,»printer»)

This function returns 4 because «n» is the fourth character in the word «printer.»

You can also search for words within other words. For example, the function

=SEARCH(«base»,»database»)

returns 5, because the word «base» begins at the fifth character of the word «database». You can use the SEARCH and SEARCHB functions to determine the location of a character or text string within another text string, and then use the MID and MIDB functions to return the text, or use the REPLACE and REPLACEB functions to change the text. These functions are demonstrated in Example 1 in this article.

Important: 

  • These functions may not be available in all languages.

  • SEARCHB counts 2 bytes per character only when a DBCS language is set as the default language. Otherwise SEARCHB behaves the same as SEARCH, counting 1 byte per character.

The languages that support DBCS include Japanese, Chinese (Simplified), Chinese (Traditional), and Korean.

Syntax

SEARCH(find_text,within_text,[start_num])

SEARCHB(find_text,within_text,[start_num])

The SEARCH and SEARCHB functions have the following arguments:

  • find_text    Required. The text that you want to find.

  • within_text    Required. The text in which you want to search for the value of the find_text argument.

  • start_num    Optional. The character number in the within_text argument at which you want to start searching.

Remark

  • The SEARCH and SEARCHB functions are not case sensitive. If you want to do a case sensitive search, you can use FIND and FINDB.

  • You can use the wildcard characters — the question mark (?) and asterisk (*) — in the find_text argument. A question mark matches any single character; an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character.

  • If the value of find_text is not found, the #VALUE! error value is returned.

  • If the start_num argument is omitted, it is assumed to be 1.

  • If start_num is not greater than 0 (zero) or is greater than the length of the within_text argument, the #VALUE! error value is returned.

  • Use start_num to skip a specified number of characters. Using the SEARCH function as an example, suppose you are working with the text string «AYF0093.YoungMensApparel». To find the position of the first «Y» in the descriptive part of the text string, set start_num equal to 8 so that the serial number portion of the text (in this case, «AYF0093») is not searched. The SEARCH function starts the search operation at the eighth character position, finds the character that is specified in the find_text argument at the next position, and returns the number 9. The SEARCH function always returns the number of characters from the start of the within_text argument, counting the characters you skip if the start_num argument is greater than 1.

Examples

Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet. For formulas to show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to see all the data.

Data

Statements

Profit Margin

margin

The «boss» is here.

Formula

Description

Result

=SEARCH(«e»,A2,6)

Position of the first «e» in the string in cell A2, starting at the sixth position.

7

=SEARCH(A4,A3)

Position of «margin» (string for which to search is cell A4) in «Profit Margin» (cell in which to search is A3).

8

=REPLACE(A3,SEARCH(A4,A3),6,»Amount»)

Replaces «Margin» with «Amount» by first searching for the position of «Margin» in cell A3, and then replacing that character and the next five characters with the string «Amount.»

Profit Amount

=MID(A3,SEARCH(» «,A3)+1,4)

Returns the first four characters that follow the first space character in «Profit Margin» (cell A3).

Marg

=SEARCH(«»»»,A5)

Position of the first double quotation mark («) in cell A5.

5

=MID(A5,SEARCH(«»»»,A5)+1,SEARCH(«»»»,A5,SEARCH(«»»»,A5)+1)-SEARCH(«»»»,A5)-1)

Returns only the text enclosed in the double quotation marks in cell A5.

boss

Need more help?

Функция ПОИСК (SEARCH) в Excel используется для определения расположения текста внутри какого-либо текста и указания его точной позиции.

Содержание

  1. Что возвращает функция
  2. Синтаксис
  3. Аргументы функции
  4. Дополнительная информация
  5. Примеры использования функции ПОИСК в Excel
  6. Пример 1. Ищем слово внутри текстовой строки (с начала)
  7. Пример 2. Ищем слово внутри текстовой строки (с указанием стартовой позиции поиска)
  8. Пример 3. Поиск слова при наличии нескольких совпадений в тексте
  9. Пример 4. Используем подстановочные знаки при работе функции ПОИСК в Excel

Что возвращает функция

Функция возвращает числовое значение, обозначающее стартовую позицию искомого текста внутри другого текста. Позиция обозначает порядковый номер символа, с которого начинается искомый текст.

Синтаксис

=SEARCH(find_text, within_text, [start_num]) — английская версия

=ПОИСК(искомый_текст;просматриваемый_текст;[начальная_позиция]) — русская версия

Аргументы функции

  • find_text (искомый_текст) — текст или текстовая строка которую вы хотите найти;
  • within_text (просматриваемый_текст) — текст, внутри которого вы осуществляете поиск;
  • [start_num] ([начальная_позиция]) — числовое значение, обозначающее позицию, с которой вы хотите начать поиск. Если не указать этот аргумент, то функция начнет поиск с начала текста.

Дополнительная информация

  • Если стартовая позиция поиска не указана, то поиск текста осуществляется сначала текста;
  • Функция не чувствительна к регистру. Если вам нужна чувствительность к регистру, то используйте функцию НАЙТИ;
  • Функция может обрабатывать подстановочные знаки. В Excel существует три подстановочных знака — ?, *, ~.
    • знак «?» — сопоставляет любой одиночный символ;
    • знак «*» — сопоставляет любые дополнительные символы;
    • знак «~» — используется, если нужно найти сам вопросительный знак или звездочку.
  • Функция возвращает ошибку, в случае если искомый текст не найден.

Примеры использования функции ПОИСК в Excel

Пример 1. Ищем слово внутри текстовой строки (с начала)

Функция ПОИСК в Excel

На примере выше видно, что когда мы ищем слово «доброе» в тексте «Доброе утро», функция возвращает значение «1», что соответствует позиции слова «доброе» в тексте «Доброе утро».

Так как функция не чувствительна к регистру, нет разницы каким образом мы указываем искомое слово «доброе», будь то «ДОБРОЕ», «Доброе», «дОброе» и.т.д. функция вернет одно и то же значение.

Если вам необходимо осуществить поиск чувствительный к регистру — используйте функцию НАЙТИ в Excel.

Telegram Logo Больше лайфхаков в нашем Telegram Подписаться

Пример 2. Ищем слово внутри текстовой строки (с указанием стартовой позиции поиска)

Функция ПОИСК в Excel

Третий аргумент функции указывает на порядковый номер позиции внутри текста, с которой будет осуществлен поиск. На примере выше, функция возвращает значение «1» при поиске слова «доброе» в тексте «Доброе утро», начиная свой поиск с первой позиции.

Вместе с тем, если мы указываем функции, что поиск следует начинать со второго символа текста «Доброе утро», то есть функция в этом случае видит текст как «оброе утро» и ищет слово «доброе», то результатом будет ошибка.

Если вы не указываете в качестве аргумента стартовую позицию для поиска, функция автоматически начнет поиск  с начала текста.

Пример 3. Поиск слова при наличии нескольких совпадений в тексте

Функция ПОИСК в Excel

Функция начинает искать текст со стартовой позиции которую мы можем указать в качестве аргумента, или она начнет поиск с начала текста автоматически. На примере выше, мы ищем слово «доброе » в тексте «Доброе доброе утро» со стартовой позицией для поиска «1». В этом случае функция возвращает «1», так как первое найденное слово «Доброе» начинается с первого символа текста.

Если мы укажем функции начало поиска, например, со второго символа, то результатом вычисления функции будет «8».

Пример 4. Используем подстановочные знаки при работе функции ПОИСК в Excel

Функция ПОИСК в Excel

При поиске функция учитывает подстановочные знаки. На примере выше мы ищем текст «c*l». Наличие подстановочного знака «*» в данном запросе обозначает что мы ищем любо слово, которое начинается с буквы «c» и заканчивается буквой «l», а что между этими двумя буквами неважно. Как результат, функция возвращает значение «3», так как в слове «Excel», расположенном в ячейке А2 буква «c» находится на третьей позиции.

The SEARCH function returns the position (as a number) of one text string inside another. If there is more than one occurrence of the search string, SEARCH returns the position of the first occurrence. SEARCH is not case-sensitive but does support wildcards. Use the FIND function to perform a case-sensitive find. When SEARCH does not find anything, it returns a #VALUE! error. Note that when find_text is empty, SEARCH will return 1. This can cause a false positive when find_text is an empty cell.

Basic Example

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!

Note that text values entered directly into SEARCH must be enclosed in double-quotes («»).

TRUE or FALSE result

To force a TRUE or FALSE result, nest SEARCH inside the ISNUMBER function. ISNUMBER returns TRUE for numbers and FALSE for anything else. 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, and ISNUMBER returns FALSE. 

Start number

The SEARCH function has an optional argument called start_num, that controls where SEARCH should begin looking for a substring. To find the first match of «the», you can omit start_num, which defaults to 1:

=SEARCH("the","The cat in the hat") // returns 1

To start searching at character 4, enter 4 for start_num:

=SEARCH("the","The cat in the hat",4) // returns 12

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 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»:

=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

However, it is possible to use 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, 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.

If cell contains

To return a custom result with the SEARCH function, use 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.

Notes

  • SEARCH returns the position of the first find_text in within_text.
  • Start_num is optional and defaults to 1.
  • Use the FIND function for a case-sensitive search.
  • SEARCH allows the wildcard characters question mark (?) and asterisk (*), in find_text.
    • ? matches any single character and
    • * matches any sequence of characters.
    • To find a literal ? or *, use a tilde (~) before the character, i.e. ~* and ~?.

The SEARCH function in Excel is categorized under text or string functions, but the output returned by this function is an integer. The SEARCH function gives us the position of a substring in a given string when we provide a parameter of the position to search from. Thus, this formula takes three arguments: substring, the string itself, and position to start the search.

For example, suppose we want to search the “Thank” substring in the provided text or string “Thank you.” Here, we need to find the “Thank” word using the SEARCH function, which will return the word “Thank” location.

=SEARCH(“Thank,” B8). The output will be 1.

The SEARCH function is a text function used to find the location of a substring in a string/text.

The SEARCH function can be used as a worksheet function. It is not case-sensitive.

Table of contents
  • Excel SEARCH Function
    • SEARCH Formula in Excel
    • Explanation
    • How to Use the Search Function in excel? (with Examples)
      • Example #1
      • Example #2
      • Example #3
      • Example #4
    • Things to Remember
    • Search Function in Excel Video
    • Recommended Articles

SEARCH Formula in Excel

Below is the SEARCH formula in Excel.

Search Function Formula

Explanation

Excel SEARCH function has three-parameter two (find_text, within_text) are compulsory parameters and one (start_num) is optional.

Compulsory Parameter:

  • find_text: find_text refers to the substring/character you want to search within a string or the text you want to find out.
  • within_text:. Where your substring is located or where you perform the find_text.

Optional Parameter:

  • [start_num]:: from where you want to start the SEARCH within the text in excelExcel provides the functionality that helps you to search for text in the file. You can use Find and Search function to search for a specific text cell value and arrive at the result.read more. If omitted, SEARCH considers it as 1 and star search from the first character.

How to Use the Search Function in excel? (with Examples)

The SEARCH function is very simple and easy to use. Let us understand the working of the SEARCH function in some examples.

You can download this Search Function Excel Template here – Search Function Excel Template

Example #1

Let us search the “Good” substring in the given text or string. Here, we have found the “Good” word using the SEARCH function, which will return the word “Good” location in the “Good morning.”

=SEARCH(“Good,” B6) and output will be 1.

Suppose two matches are found for “Good,” then SEARCH in Excel will give you the first match value. However, if you want the other good location, then you use the =SEARCH(“Good,” B7, 2) [start_num] as 2 then it will give you the place of the second match value, and the output will be 6.

Search Function Example 1

Example #2

In this example, we will filter out the first and last names from the full names using the SEARCH in excelSearch function gives the position of a substring in a given string when we give a parameter of the position to search from. As a result, this formula requires three arguments. The first is the substring, the second is the string itself, and the last is the position to start the search.read more.

For first name=LEFT(B12,SEARCH(” “,B12)-1)

Search Function Example 2

For last name=RIGHT(B12,LEN(B12)-SEARCH(” “,B12))

Search Function Example 2-1

Example #3

Suppose there is a set of IDs. First, you have to find the _ location within IDs, then use Excel SEARCH to find the “_” location within IDs.

=SEARCH(“_,” B27), and output will be 6.

Example 3

Example #4

Let us understand the working of SEARCH in excel with wildcards charactersIn Excel, wildcards are the three special characters asterisk, question mark, and tilde. Asterisk denotes multiple characters, a question mark denotes a single character, and a tilde denotes the identification of a wild card character.read more.

Example -4

Consider the table and search for the next 0 within the text A1-001-ID.

And start position will be 1, then =SEARCH(“?” &I8, J8, K8) output will be 3 because “?” neglects the one character before the 0, and output will be 3.

For the second row within a given table, the search result for A within B1-001-AY.

It will be 8, but if we use “*” in search, it will give you the 1 as location output because it will neglect all characters before “A,” and output will be 1 for it =SEARCH(“*” &I9, J9).

Similarly, for “J” 8 =SEARCH(I10,J10,K10) and 7 for  =SEARCH(“?”&I10,J10,K10).

Similarly, for fourth row, the output will be 8 for =SEARCH(I11,J11,K11) and 1 for =SEARCH(“*” &I11,J11,K11)

Things to Remember

  • It is not case-sensitive.
    • It considers tanuj and TANUJ as the same value, which means it does not distinguish between lower and upper case.
  • It is also allowed wildcard characters, i.e., “?”, “*,” and “~” tilde.
    • “?” is used to find a single character.
    • “*” is used for match sequences.
    • If we want to search the “*” or”? “, we need to insert the “~” before the character.
  • It returns the #VALUE! Error if there is no matching string is found in the within_text.

Suppose in the below example. We are searching for a substring “a” within the “Name” column. If found, it will return the location of a within name else. In addition, it will give a #VALUE error#VALUE! Error in Excel represents that the reference cell the user has either entered an incorrect formula or used a wrong data type (mostly numerical data). Sometimes, it is difficult to identify the kind of mistake behind this error.read more, as shown below.

Example 5

Search Function in Excel Video

Recommended Articles

This article is a guide to the SEARCH Function in Excel. Here, we discuss the SEARCH formula and how to use the SEARCH function, along with Excel examples and downloadable Excel templates. You may also look at these useful functions in Excel: –

  • Search Box in ExcelA search box in Excel finds the needed data by typing into it, then filters the data and displays only that much info. When working with large datasheets, this simple tool may save a lot of time.read more
  • Excel Substring FunctionThe substring function in Excel is a built-in integrated function that is categorized under the TEXT function and is used to extract a string from a combination of string.read more
  • Filters in Excel
  • True Function in Excel

In this article, we will learn how to use SEARCH function in Microsoft Excel.

The MS-Excel SEARCH function returns the position of the first character of sub-string or search_text in a string. The function does not discriminate between uppercase and lowercase letters while searching. Unlike FIND, SEARCH allows wildcard characters, like question mark (?) and asterisk (*). The question mark (?) matches any single character and the asterisk (*) matches any sequence of character. However, in case we want to find an actual question mark (?) or asterisk (*), we type a tide (~) before the character. If the sub-string is not found within the string, then the function will return #VALUE error. SEARCH function can be used as powerful string method function when combined with MID function.

The function arguments / syntax are: image 1   We have dummy data in column A. Column B contains the text which we will search for. And column C has the starting position of the search. And, here in column D, we will enter the SEARCH function. image 2   1st Example:- In the first example, we will search “AGE” in cell A7. image 3   Follow the steps given below:-

  • Enter the function in cell C7
  • =SEARCH(«AGE»,A7,1)
  • Press Enter

image 4   It returns to 1 because “SEARCH” is looking from the first character, and it found AGE beginning from the 1st character. So it gives us 1 here. 2nd Example:- In this example, we will search for “C” and we give the starting number as zero or negative number as the starting position. image 5   Follow the steps given below:-

  • Enter the function in cell C8
  • =SEARCH(«c»,A8,-1), Press Enter

image 6   The Function has returned #VALUE error because neither negative nor 0 can be the starting position. 3rd Example:- In this example, we will show you what if we have to find the text which is there multiple times in the string. image 7   Follow the steps given below:-

  • Enter the function in cell C9
  • =SEARCH(«o»,A9,5), Press Enter

image 8   The function has ignored the “o” which is at 4th position and the function returns to 9 as the position. Because it ignored the first “o” and started looking from 5th character onwards. However, it returns the overall position of the string. 4th Example:- In this example, we’ll search for wildcard characters’ position within cell A10. image 9   Follow the steps given below:-

  • First we’ll look for (*) asterisk sign, enter the function in cell C10
  • =SEARCH(«*»,A10,1), Press Enter

image 10   The function has returned 1, because we cannot find any wildcard without using tilde. As we use tilde (~) as a marker to indicate that the next character is a literal, we will insert (~) tilde before (*) asterisk.

  • Enter this function =SEARCH(«~*»,A10,1)
  • Now it returns 16 as the position

image 11   We can also look for question mark:-

  • Enter the function in same cell C10
  • =SEARCH(«~?»,A10,1), Press Enter

image 12   We can see that function gave us “37” as the position of (?) question mark. 5th Example:- In this example, we’ll learn how to enter SEARCH function to search “?of?”. image 13   Follow the steps given below:-

  • Enter the function in cell C11
  • =SEARCH(«?of?»,A11,1)
  • Press Enter

image 14   We scan to see that function has returned 6 because it matches “soft” which is present in the mid of “Microsoft Excel” string and hence the value is 6. Note:- (?) question mark wildcard denotes any single character. 6th Example:- In this example, we’ll learn another use of wildcard in SEARCH function. image 15   Follow the steps given below:-

  • Enter the function in cell C12
  • =SEARCH(«m*t»,A12,1)

Note: — In first argument, we tell the function to look for the string which starts with “m” and ends with “t”, and we will put asterisk (*) in between.

  • Press Enter

image 16   “Microsoft Excel” and it finds there is a string which starts with “M” and ends with “L”. No matter how many characters are there in between and hence it returns 1. Because (*) asterisk wild character matches any sequence of character. So, this is how SEARCH function works in different situation.   image 48

Video: How to use SEARCH function in Microsoft Excel

Click on the video link for quick reference to the use of SEARCH function. Subscribe to our new channel and keep learning with us! https://www.youtube.com/watch?v=HW0QP1JxeuU

If you liked our blogs, share it with your friends on Facebook. And also you can follow us on Twitter and Facebook. We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write us at info@exceltip.com

Like this post? Please share to your friends:
  • Use of the word vet
  • Use recently in a sentence for each word
  • Use of the word unless in a sentence
  • Use rank in excel
  • Use of the word towards