Expires in:
This article shows how to use Excel's SEARCH function to locate characters inside text and extract dynamic substrings, like the username portion of an email. It is practical for analysts, Excel users, and anyone who needs reliable, formula-driven text cleanup. You will learn the SEARCH syntax, how to combine it with LEFT, MID, and RIGHT, and common pitfalls to avoid.

What You'll Learn / Key Take-Aways
- How the SEARCH function finds the position of a character or string in Excel and how it differs from FIND.
- How to combine SEARCH with LEFT to extract the username portion of an email address.
- How to use the optional start_num parameter to skip first occurrences.
- Practical variations: extracting text after a symbol, extracting domain, and protecting against missing values.
- Common pitfalls and quick pro tips to make formulas robust.
## Why SEARCH matters
SEARCH is a text function that returns the position of a character or substring inside another text string. It is especially useful when the number of characters to return is not fixed. Unlike LEFT, MID, and RIGHT, which need a fixed numeric length, SEARCH makes the length dynamic by telling you where a character appears.
Definition
- SEARCH(find_text, within_text, [start_num])
- find_text: the character or substring you want to find, in quotes if literal.
- within_text: the cell or string to search.
- start_num: optional. The character position to start searching from.
Behavior
- Returns the index (1-based) of the first character in the found substring.
- If the string is not found it returns a #VALUE! error.
- SEARCH is not case sensitive. Use FIND when you need case sensitivity.
## Extracting a username from an email using SEARCH and LEFT
Problem: You have emails like `jennifer.j.mcgrath@gmail.com` in column N and you want the username everything before the @ symbol.
Approach: Use LEFT to take characters from the left, but instead of a fixed number use SEARCH to find the position of the at sign and subtract one so you do not include the @.
Formula example
- If the email is in N2, use:
`=LEFT(N2, SEARCH("@", N2) - 1)`
Explanation
- `SEARCH("@", N2)` returns the position of the at sign. If the at sign is at position 16, SEARCH returns 16.
- Subtract 1 to exclude the at sign and return only the username characters.
- LEFT then returns that many characters from the left of the email string.
Copy this formula down and it will dynamically extract the username regardless of username length.
## Using start_num to find subsequent occurrences
If your string contains multiple instances of the same character and you want the second or third one, use the optional start_num.
Example: find the second percent sign in a text
- `=SEARCH("%", A11, 10)`
This tells SEARCH to start at character 10 and continue scanning to the right. If the second percent sign appears at position 13, SEARCH returns 13.
This is useful when you want to find the nth occurrence by chaining searches. For example, to find the position of the second occurrence programmatically you can nest SEARCH functions or use helper columns.
## Extracting text after a symbol using MID, LEN, and SEARCH
To get everything after the at sign, use MID combined with LEN and SEARCH:
- `=MID(N2, SEARCH("@", N2) + 1, LEN(N2) - SEARCH("@", N2))`
Explanation
- `SEARCH("@", N2) + 1` gives the starting position one character after the @.
- `LEN(N2) - SEARCH("@", N2)` gives the number of characters remaining after the @.
- MID then returns the substring of that length.
If you only want the domain up to the first dot after the at sign you can combine SEARCH with another SEARCH for the dot, or use FIND if you care about case.
## SEARCH vs FIND: when to use which
- SEARCH: not case sensitive, supports wildcards, generally more flexible for user data.
- FIND: case sensitive and slightly stricter. Use FIND only when case is important.
I default to SEARCH unless I specifically need case sensitivity.
## Making formulas robust
Wrap SEARCH in IFERROR to avoid #VALUE! when the searched character is missing. For example:
- `=IFERROR(LEFT(N2, SEARCH("@", N2) - 1), "")`
This returns an empty string when the email is malformed or missing, instead of an error. You can also return a message like "invalid email" if you prefer.
## Example workflows and variations
1) Extract username (before @)
- `=LEFT(N2, SEARCH("@", N2) - 1)`
2) Extract domain (after @)
- `=MID(N2, SEARCH("@", N2) + 1, LEN(N2) - SEARCH("@", N2))`
3) Extract subdomain or first label after @ (up to first dot)
- `=LEFT( MID(N2, SEARCH("@", N2) + 1, LEN(N2)), SEARCH(".", MID(N2, SEARCH("@", N2) + 1, LEN(N2))) - 1 )`
This nests MID to get the part after @, then finds the dot inside that substring, and takes the left portion up to the dot.
4) Find the nth occurrence of a character
- Use SEARCH with start_num. For the second occurrence of ":": `=SEARCH(":", A1, SEARCH(":", A1) + 1)`
## Additional Tips, Pitfalls to Avoid & Pro Advice
- Always account for missing characters. Use IFERROR or test with ISNUMBER(SEARCH(...)).
- Remember SEARCH is 1-based. Position 1 is the first character.
- If you subtract 1 from the SEARCH result, ensure the result does not become zero or negative. That happens when the searched symbol is at position 1 or not found. Protect with an IF.
- Use TRIM to clean leading or trailing spaces before applying SEARCH if user-entered data may contain stray spaces.
- When you need case sensitivity, switch to FIND. If you need wildcard support, use SEARCH.
- For performance: very large sheets with many nested SEARCH calls can get slower. Consider helper columns to store intermediate positions.
## FAQ
Q: How do I extract the username from an email in Excel?
A: Use `=LEFT(email_cell, SEARCH("@", email_cell) - 1)`. This finds the @ and returns the characters to its left.
Q: What is the difference between SEARCH and FIND in Excel?
A: SEARCH is not case sensitive and supports wildcards. FIND is case sensitive and does not support wildcards. Use SEARCH for most user data.
Q: How can I extract the domain after the at symbol?
A: Use `=MID(email_cell, SEARCH("@", email_cell) + 1, LEN(email_cell) - SEARCH("@", email_cell))` to return everything after the @.
Q: What if the email does not contain an at sign and my formula errors out?
A: Wrap the formula with IFERROR or check first: `=IFERROR(LEFT(N2, SEARCH("@", N2) - 1), "")` to return an empty string instead of an error. Or use `IF(ISNUMBER(SEARCH("@", N2)), ..., "invalid email")`.
Q: How do I find the second occurrence of a character?
A: Use the optional start_num. For the second occurrence of ":": `=SEARCH(":", A1, SEARCH(":", A1) + 1)`.
Q: Should I use SEARCH for all text extraction tasks?
A: SEARCH is great when you need a dynamic position and do not care about case. If you need strict case sensitivity use FIND. For more complex patterns consider Power Query or regular expressions in other tools.
## Summary of Key Points / Take-Home Messages
- SEARCH returns the position of a substring and is perfect for dynamic text extraction.
- Combine SEARCH with LEFT, MID, and RIGHT to extract usernames, domains, and other pieces of text.
- Subtract one from SEARCH when you need to exclude the delimiter character itself.
- Use IFERROR, TRIM, and helper columns to make formulas robust and performant.
- Use FIND only when case sensitivity is required.
Practice these patterns on a sample email column and you will quickly be able to handle most common text extraction problems in Excel.






