SEARCH Function¶
The SEARCH function in Excel is used to find the position of a specific substring within a text string. This function
is case-insensitive, which means it treats "A" and "a" as the same. It is particularly useful for finding text patterns
within strings, aiding in text processing and manipulation tasks.
Syntax¶
SEARCH(find_text, within_text, [start_num])
find_text: The text you want to find. This can be a single character or a string.within_text: The text in which you want to search for thefind_text.start_num(optional): The position inwithin_textto start the search. The default is 1, which makes the search start at the first character.
Returns¶
The SEARCH function returns the character position of the first occurrence of find_text in within_text. If the
find_text is not found, it returns a #VALUE! error.
Key Features¶
- Case-Insensitive: Unlike the
FINDfunction,SEARCHdoes not differentiate between uppercase and lowercase letters. - Flexible Start Point: By using the
start_numargument, you can control where the search begins. This is useful for skipping over parts of the text. - Error Handling: Useful in combination with functions like
IFERRORto gracefully handle instances where thefind_textis not found.
Example¶
Suppose you want to find the position of the substring "cat" in the text "Concatenation".
=SEARCH("cat", "Concatenation")
This formula returns 4, since "cat" begins at the fourth character of "Concatenation".
Notes¶
- If
find_textis not found, theSEARCHfunction will return the#VALUE!error. It is often useful to wrap the SEARCH function in anIFERRORfunction to handle errors gracefully. - The
start_numargument is useful if you're working with large text strings and only want to search beyond a certain point. SEARCHcan be used for wildcard searches by incorporating the*wildcard to match any number of characters or?to match a single character.
Wildcard Support¶
The SEARCH function supports wildcards to find text patterns:
- Asterisk (*): Matches any number of characters. For example,
SEARCH("cat*", "Concatenation")would return 4. - Question Mark (?): Matches any single character. For example,
SEARCH("c?t", "Concatenation")would not find a match because "c" is followed by "a", not just any single character before "t".
Handling Errors¶
To handle cases where the text is not found, wrap the SEARCH function in the IFERROR function:
=IFERROR(SEARCH("dog", "Concatenation"), "Not found")
If "dog" is not found in "Concatenation", this formula returns "Not found" instead of an error.
Comparison with FIND¶
- The
SEARCHfunction is case-insensitive, while theFINDfunction is case-sensitive. - If you need to differentiate between cases (upper and lower), consider using
FINDinstead ofSEARCH.