TEXTBEFORE Function

Excel 365, Excel 2021+

Summary

The TEXTBEFORE function extracts all text that appears before a specified delimiter within a text string. Perfect for parsing filenames, URLs, email addresses, or any structured text data where you need everything before a consistent separator.

Syntax

=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

Parameters

Parameter Type Required Description
text Text Yes The full text string to search within (no wildcards)
delimiter Text Yes Character or string marking where to split (required)
instance_num Number No Which occurrence of delimiter to use (default=1, negative=from end)
match_mode Number No 0=case sensitive (default), 1=case insensitive
match_end Number No 0=don't match end (default), 1=treat end as delimiter
if_not_found Any No Value to return if no match (default=#N/A)

Using the TEXTBEFORE Function

TEXTBEFORE revolutionizes text parsing in Excel by letting you extract everything before a delimiter with precision control. Ideal for cleaning data from imports, extracting usernames from emails, getting folder paths from filenames, or processing structured text from web scraping.

Common TEXTBEFORE Examples

Basic Delimiter Extraction

=TEXTBEFORE("Little Red Riding Hood's red hood", "Red")

Returns "Little" - everything before first "Red"

Multiple Instances (Forward)

=TEXTBEFORE("Little red Riding Hood's red hood", "red", 2)

Returns "Little red Riding Hood's" - before 2nd "red"

Multiple Instances (Backward)

=TEXTBEFORE("Little red Riding Hood's red hood", "red", -2)

Returns "Little" - before 2nd "red" counting from end

Case Insensitive

=TEXTBEFORE("Little red Riding Hood's red hood", "Red", 1, 1)

Returns "Little red Riding" using case-insensitive match

Extract Username from Email

=TEXTBEFORE("[email protected]", "@")

Returns "john.doe" from email address

Filename Without Extension

=TEXTBEFORE("report2024.xlsx", ".")

Returns "report2024"

Frequently Asked Questions

Empty delimiter matches immediately: positive instance_num returns empty text, negative returns full text.

TEXTBEFORE handles multiple instances, case sensitivity, and end-matching natively - much more powerful.

No, wildcards are not supported in the text or delimiter parameters.

Common Errors and Solutions

#VALUE! error

Cause: instance_num = 0 or greater than text length

Solution: Use valid instance_num (1+ for forward, -1+ for backward)

#N/A error

Cause: Delimiter not found in text

Solution: Verify delimiter exists or use if_not_found parameter

#N/A error

Cause: instance_num exceeds delimiter occurrences

Solution: Reduce instance_num or check text content

Notes

  • Available only in Excel 365 and Excel 2021+
  • Opposite of TEXTAFTER function
  • Negative instance_num searches from text end
  • Empty text returns empty result
  • Perfect companion to TEXTSPLIT for advanced parsing

Compatibility

Available in: Excel 365, Excel 2021

Not available in: Excel 2019, Excel 2016, Excel 2013, Excel 2010, Excel 2007

Content last reviewed: December 9, 2025
Update frequency: As needed
Excel versions tested: Excel 365, Excel 2021+