SEARCH

Text Functions
(4.8/5)

Returns the position of the first occurrence of find_text within within_text. Case-insensitive search function essential for text parsing, data extraction, and flexible string manipulation in Excel.

Interactive Formula Tester

=SEARCH("test@example.com")

Complete Theory & Understanding

Master the fundamentals of Excel SEARCH function

Core Concept

The SEARCH function is Excel's case-insensitive text search tool that returns the position of the first occurrence of find_text within within_text. It's essential for text parsing, data extraction, and flexible string manipulation, particularly when case sensitivity doesn't matter.

Why Use SEARCH?

  • Search text without case sensitivity concerns
  • Find @ symbol to extract domains
  • Check if specific text exists (case-insensitive)
  • Combine with LEFT, RIGHT, MID for extraction

Key Characteristics

Case-Insensitive

Matches text regardless of case

SEARCH("excel", "Excel Functions") returns 1

Position Return

Returns numeric position of found text

SEARCH("World", "Hello World") returns 7

Start Position

Can specify starting position for search

SEARCH("text", A1, 5) starts from position 5

Wildcard Support

Supports wildcards ? and *

SEARCH("ex*", A1) finds text starting with "ex"

Function Anatomy

=SEARCH(parameters...)
Required
Parameters:

Function-specific parameters

Returns
Return Value:

Function-specific return type

Primary Use Cases

Flexible Text Search

Search text without case sensitivity concerns

Email Processing

Find @ symbol to extract domains

Data Validation

Check if specific text exists (case-insensitive)

String Manipulation

Combine with LEFT, RIGHT, MID for extraction

Theory Summary

Precise

Exact matching required

Position-Based

Returns numeric position

Error-Safe

Handles missing text gracefully

Syntax & Parameters

=SEARCH(find_text, within_text, start_num)
Required
find_text:

The text to find (case-insensitive)

Required
within_text:

The text to search within

Optional
start_num:

The position number to start searching from (default: 1)

Returns
Return Value:

Position number of first occurrence, or #VALUE! if not found

Description: Returns the position of the first occurrence of find_text within within_text. Case-insensitive.

Interactive Examples

Basic Text Search

Find position of text within string (case-insensitive)

"Hello World"
=SEARCH("world", "Hello World")
7

Returns position 7 where 'World' starts (case-insensitive match)

VBA Implementation & Automation

Basic SEARCH in VBA

Simple VBA implementation of SEARCH function

' Basic SEARCH in VBA
Dim position As Long
position = Application.WorksheetFunction.Search("@", Range("A1").Value)
Range("B1").Value = position

' Using VBA SEARCH function
Dim text As String
text = "Hello World"
Dim pos As Long
pos = Application.WorksheetFunction.Search("world", text)
Debug.Print pos ' Output: 7 (case-insensitive)

' Loop through range and search text
Sub SearchTextInRange()
    Dim cell As Range
    Dim searchText As String
    searchText = "@"
    For Each cell In Range("A1:A10")
        If Not IsEmpty(cell.Value) Then
            On Error Resume Next
            Dim pos As Long
            pos = Application.WorksheetFunction.Search(searchText, cell.Value)
            If Err.Number = 0 Then
                cell.Offset(0, 1).Value = pos
            Else
                cell.Offset(0, 1).Value = "Not Found"
                Err.Clear
            End If
            On Error GoTo 0
        End If
    Next cell
End Sub

Advanced SEARCH with Error Handling

Comprehensive SEARCH implementation with error handling

' Function to search text with error handling
Function SearchTextSafe(findText As String, withinText As String, Optional startNum As Long = 1) As Variant
    On Error Resume Next
    Dim pos As Long
    pos = Application.WorksheetFunction.Search(findText, withinText, startNum)
    If Err.Number = 0 Then
        SearchTextSafe = pos
    Else
        SearchTextSafe = "Not Found"
        Err.Clear
    End If
    On Error GoTo 0
End Function

' Extract email domain using SEARCH
Function ExtractDomain(email As String) As String
    On Error Resume Next
    Dim pos As Long
    pos = Application.WorksheetFunction.Search("@", email)
    If Err.Number = 0 And pos > 0 Then
        ExtractDomain = Right(email, Len(email) - pos)
    Else
        ExtractDomain = "Invalid Email"
    End If
    On Error GoTo 0
End Function

' Search with wildcards
Function SearchWithWildcard(withinText As String, pattern As String) As Variant
    On Error Resume Next
    Dim pos As Long
    pos = Application.WorksheetFunction.Search(pattern, withinText)
    If Err.Number = 0 Then
        SearchWithWildcard = pos
    Else
        SearchWithWildcard = "Not Found"
    End If
    On Error GoTo 0
End Function

' Usage example
Sub TestSearchFunctions()
    Range("B1").Value = SearchTextSafe("@", Range("A1").Value)
    Range("C1").Value = ExtractDomain(Range("A1").Value)
End Sub

Business Applications

Email Domain Extraction

Extract domain from email addresses

=RIGHT(A1, LEN(A1)-SEARCH("@", A1))

Text Parsing

Parse text using delimiters (case-insensitive)

=MID(A1, SEARCH("-", A1)+1, 10)

Data Validation

Check if text contains substring (case-insensitive)

=IF(ISNUMBER(SEARCH("test", A1)), "Found", "Not Found")

Wildcard Search

Search using wildcards ? and *

=IF(ISNUMBER(SEARCH("ex*", A1)), "Found", "Not Found")

Common Issues & Solutions

#VALUE! Error

SEARCH returns #VALUE! when text is not found

=IFERROR(SEARCH("text", A1), "Not Found")

Solution: Use IFERROR or ISNUMBER to handle errors: =IFERROR(SEARCH("text", A1), "Not Found") or =IF(ISNUMBER(SEARCH("text", A1)), "Found", "Not Found")

Wildcard Characters

SEARCH treats ? and * as wildcards, not literal characters

=SEARCH("~?", A1)

Solution: Use ~ before wildcard to search for literal character: =SEARCH("~?", A1) to find question mark, or use FIND for exact matching

Start Position Error

start_num must be positive and within text length

=SEARCH("text", A1, MAX(1, MIN(start_num, LEN(A1))))

Solution: Ensure start_num is between 1 and LEN(within_text). Use IF to validate: =IF(start_num>0 AND start_num<=LEN(A1), SEARCH(...), #VALUE!)

Case Sensitivity Needed

When case sensitivity is required, SEARCH may not be appropriate

=FIND("text", A1)

Solution: Use FIND for case-sensitive searches, or convert both to same case for SEARCH: =SEARCH(UPPER("text"), UPPER(A1))

Performance Tips & Best Practices

⚡ Performance Optimization

  • Use SEARCH efficiently with proper error handling
  • Combine SEARCH with IFERROR to avoid repeated calculations
  • Use FIND if case sensitivity is needed (slightly faster)
  • Cache SEARCH results when used multiple times in formulas

🎯 Best Practices

  • Always use IFERROR or ISNUMBER to handle SEARCH errors
  • Use SEARCH for case-insensitive searches; FIND for case-sensitive
  • Validate start_num parameter before using in SEARCH
  • Use ~ to escape wildcard characters when searching for literal ? or *

💡 Pro Tips

  • SEARCH is case-insensitive; FIND is case-sensitive
  • SEARCH supports wildcards ? (single char) and * (multiple chars)
  • Combine SEARCH with MID, LEFT, RIGHT for text extraction
  • Use SEARCH for flexible text matching when case doesn't matter