Templates, guides & honest tool reviews for small business

Monday, November 30, 2026

TEXTBEFORE and TEXTAFTER in Excel: Cut Text at a Delimiter

Section: Excel & Google Sheets

TEXTBEFORE and TEXTAFTER - explanatory illustration for TEXTBEFORE and TEXTAFTER in Excel
Illustration: TEXTBEFORE and TEXTAFTER

TEXTBEFORE and TEXTAFTER in Excel cut a piece of text at a delimiter and return what sits on either side of it. =TEXTBEFORE(A2," ") on "Marcus Aurelius" gives Marcus, and =TEXTAFTER(A2," ") gives Aurelius. Together they replace the LEFT, FIND and MID combination people have written by hand for years, with one argument that does the counting. This guide covers the syntax of both functions, the arguments that matter, instance numbers, case sensitivity, the errors and the versions that have them.

What the two functions do

Microsoft describes TEXTBEFORE as returning the text that occurs before a given character or string, and TEXTAFTER as returning the text after it. Each is the opposite of the other, so the pair splits a cell in two in a single step.

Two rules apply to both. Wildcard characters are not allowed in the text or the delimiter, so a delimiter of "*" is the character itself, not a pattern. And if the text is an empty string, Excel returns empty text.

Which Excel versions have them

Microsoft lists both functions for Excel for Microsoft 365 on Windows and Mac, Excel 2024 on Windows and Mac, and Excel for the web. TEXTAFTER is also listed for Office on the iPhone. They are not listed for Excel 2021, 2019 or 2016, and on those versions the name is not recognised, which shows as a #NAME? error. If a formula that works on your machine fails on a colleague's, the version is the first thing to check.

The syntax

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

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

The arguments are identical in both functions. Only the direction of the cut changes.

The arguments that matter

  • text is the cell or string you are searching in. Required.
  • delimiter is the character or string that marks the cut. Required. It can be more than one character, such as ", " or " - ".
  • instance_num is which occurrence of the delimiter to use. It defaults to 1, and a negative number starts the count from the end.
  • match_mode sets case sensitivity: 0 is case sensitive and is the default, 1 ignores case.
  • match_end decides whether the end of the text counts as a delimiter: 0 does not and is the default, 1 does.
  • if_not_found is what to return when there is no match. The default is #N/A.
The arguments both functions share - explanatory illustration for TEXTBEFORE and TEXTAFTER in Excel
The arguments both functions share (explanatory illustration, not a software screenshot).

A first example: names

Microsoft's second example uses three names in a column, Marcus Aurelius, Socrates and Immanuel Kant, and cuts at the space:

  • =TEXTBEFORE(A2," ") returns Marcus, and =TEXTAFTER(A2," ") returns Aurelius.
  • On the single word Socrates there is no space, so the plain formula returns #N/A.
  • Adding match_end as 1 changes that: =TEXTBEFORE(A3," ",,,1) returns Socrates, because the end of the text is treated as a delimiter.
  • =TEXTAFTER(A3," ",,,1) returns empty text, and Microsoft wraps it as =IF(TEXTAFTER(A3," ",,,1)="",A3) to keep the original word.

The pattern is worth remembering. A first name is TEXTBEFORE with match_end on, and a last name needs the IF wrapper, because a single-word name has nothing after the space.

Splitting a name with TEXTBEFORE - explanatory illustration for TEXTBEFORE and TEXTAFTER in Excel
Splitting a name with TEXTBEFORE (explanatory illustration, not a software screenshot).

Instance numbers: the last part

Most real data has more than one delimiter. Take an invoice number like INV-2026-0042 in A2. There are two hyphens, so the instance number picks which one cuts the text:

  • =TEXTBEFORE(A2,"-") returns INV, and =TEXTAFTER(A2,"-") returns 2026-0042.
  • =TEXTBEFORE(A2,"-",2) returns INV-2026, and =TEXTAFTER(A2,"-",2) returns 0042.
  • =TEXTAFTER(A2,"-",-1) also returns 0042, counting from the end. The negative form is the safe one when the number of hyphens can change.
  • =TEXTBEFORE(A2,"-",3) returns #N/A, because there is no third hyphen.

That last case is the one that bites in a copied-down column: an instance number larger than the number of occurrences gives #N/A, not a blank. Use -1 when you want the last segment, and a fixed positive number only when the format is guaranteed.

Instance numbers on INV-2026-0042 - explanatory illustration for TEXTBEFORE and TEXTAFTER in Excel
Instance numbers on INV-2026-0042 (explanatory illustration, not a software screenshot).

The space that comes with the result

Microsoft's first example uses the text "Little red Riding Hood's red hood" and cuts at the word red. The result shown as Little is really "Little " with the space still attached, because the delimiter was the word and not the space before it. The same happens with =TEXTBEFORE(A3,"red",2), which keeps the space after Hood's.

Wrap the call in TRIM when the result feeds another formula or a lookup. =TRIM(TEXTBEFORE(A2," ")) removes the stray space, and a lookup that failed for no visible reason starts working again.

Errors and if_not_found

Microsoft lists three errors for both functions. Excel returns #N/A when the delimiter is not contained in the text. It returns #N/A when instance_num is greater than the number of occurrences of the delimiter. And it returns #VALUE! when instance_num is 0 or greater than the length of the text.

The sixth argument handles the first two without a wrapper. =TEXTBEFORE(A2,"@",1,0,0,"no address") returns the local part of an email address, or the words no address when the cell holds something else. That is cleaner than IFERROR, because it says what went wrong in the cell instead of hiding every error in the formula.

Errors from TEXTBEFORE and TEXTAFTER - explanatory illustration for TEXTBEFORE and TEXTAFTER in Excel
Errors from TEXTBEFORE and TEXTAFTER (explanatory illustration, not a software screenshot).

Case sensitivity

The default here is case sensitive, which surprises people who are used to SEARCH. Microsoft's example makes the effect plain: on the text "Little red Riding Hood's red hood", =TEXTBEFORE(A3,"Red") returns #N/A because the text has red in lower case. Set match_mode to 1 to ignore case, as in =TEXTBEFORE(A3,"red",1,1), and the same formula finds it.

Check the source data before you decide. Product codes and invoice prefixes are usually consistent, so the default is fine. Free text typed by different people is not, and there match_mode 1 saves a support ticket.

TEXTBEFORE versus LEFT and FIND

The old way to take everything before the first space was =LEFT(A2,FIND(" ",A2)-1). It still works and it still runs on Excel 2016. The new function is shorter and reports a clean #N/A when the delimiter is missing, where the old one returns #VALUE!. When you need the part after the second delimiter, the old approach needs MID and two FIND calls, and that is where TEXTBEFORE earns its place.

There is also a point where splitting stops being a formula problem. If you want every part of a delimited string at once, TEXTSPLIT returns them as a spill range, and TEXTJOIN puts them back together. For a single cut in a fixed position, LEFT, RIGHT and MID remain the simplest answer.

Questions and answers

What is the difference between TEXTBEFORE and TEXTAFTER?

TEXTBEFORE returns the part in front of the delimiter and TEXTAFTER returns the part behind it. The arguments are the same.

How do I get the last part of a string?

Use a negative instance number: =TEXTAFTER(A2,"-",-1) returns everything after the last hyphen.

Why do I get #N/A when the text clearly has the delimiter?

Case is the usual cause, since the default is case sensitive. Set match_mode to 1, or check for a non-breaking space or an extra space in the source.

Can the delimiter be more than one character?

Yes. A delimiter of ", " or " - " works, and the whole delimiter is removed from the result.

Do these functions work in Google Sheets?

Microsoft lists them for Excel only. If you build the same sheet in Google Sheets, check availability there before you copy a formula across, and use SPLIT or REGEXEXTRACT if it is missing.

Official references

العربية