Excel - TEXTBEFORE Function



TEXTBEFORE Function

The Excel TEXTBEFORE function is used to retrieve the part of the input statement before the occurrence of the delimiter/character. Executing this function in older versions like Excel 2009 and 2007 will not suffice for your data extraction and cleaning purposes. The three main text functions for string manipulation are TEXTBEFORE, TEXTAFTER, and TEXTSPLIT, which you can implement in Microsoft Excel's latest version. For example, you can retrieve the sales executive's first name through the TEXTBEFORE function.

Compatibility

The TEXTBEFORE function is available only in the following versions of Excel −

  • Excel for Microsoft 365
  • Excel for Microsoft 365 for Mac
  • Excel for the web

Syntax

The syntax of the TEXTBEFORE function is as follows −

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

Arguments

You may utilize the following arguments with the TEXTBEFORE function −

Argument Description Required / Optional
Text A text string for text manipulation. Required
Delimiter A delimiter/character/text is being searched in the input string that behaves like a marker, and a part of the text is retrieved before it. Required
instance_num It specifies the delimiters instance to fetch the resulting text. By default, its value is 1. If its value is negative, text searching is from the rear. Optional
match_mode Its value can be 0 or 1. By default, 0 is employed for case-sensitive; otherwise, use 1 for case-insensitive. Optional
match_end It matches the text rear with a delimiter. Use 1 for the exact match; otherwise, use 0 for the text that does not match the specific delimiter. Optional
If_not_found A constant value is retrieved if the matching text/delimiter is not presented in the input text. Optional

How to add the TEXTBEFORE Function in Excel?

1. First, open a new worksheet either in the Excel 365 or in the Excel for the web.

2. Double-click on the targeted cell, type the = sign, and then write TEXTBEFORE(B4, delimiter/text). You can specify the other optional arguments in this function.

3. Finally, press the Enter tab to get the result.

TEXTBEFORE Function not Working in Excel

  • If the delimiter or text is not identified in the input string, the TEXTBEFORE function will not work and will return the #N/A
  • If the instance_num is more than the length of the input text or equals zero, then the TEXTBEFORE function will give you the #VALUE!
  • The wrong cell reference given in the first argument in the TEXTBEFORE function leads to an error value.
  • The TEXTBEFORE function will not execute if you use Excel versions other than Excel 365.
  • If you use an integer value other than 0 or 1 in the match_mode argument, then the TEXTBEFORE function will retrieve the #VALUE!
  • If you set a negative or positive number other than 0 or 1 in the match_end argument, the TEXTBEFORE function will retrieve the #VALUE!

Examples of TEXTBEFORE Function

Practice the following examples to learn the use of the TEXTBEFORE function in Excel.

Example 1

In this example, enter the formula =TEXTBEFORE(B2,"-") in the C2 cell.

TEXTBEFORE Function

Once you hit the Enter button, the resulting value is Raw retrieved by the TEXTBEFORE function, which is a part of the input text string just before the delimiter.

TEXTBEFORE Function

Example 2: Multiple Delimiters in Text String

If the input string contains multiple delimiters, you can use an array to specify all the delimiters in the second argument. The statement written in the B4 cell contains so many delimiters. Write the formula =TEXTBEFORE(B4,{"'","'","-"}) in the C4 cell. In this second argument, all the delimiters are enclosed in the double quotes and separated by commas.

Multiple Delimiters in Text String

Therefore, the output is Submit customer.

Multiple Delimiters in Text String

Example 3: Case Insensitive

By default, the TEXTBEFORE function is case-sensitive, which means uppercase and lowercase characters are manipulated differently.

You enter the formula =TEXTBEFORE(B3,"park") in the D3 cell.

Case Insensitive

Once you hit the Enter button, the TEXTBEFORE function will return the #N/A error as the second argument is "park," which is not identified in the input string due to case sensitivity. The p letter in the input string is uppercase, interpreting it differently.

Case Insensitive 1

To avoid this problem, you can set the match_mode to 1 for not being case-sensitive while executing the TEXTBEFORE function.

Edit the previous formula and write =TEXTBEFORE(B3,"park",,1) in the D3 cell and press the Enter tab.

Case Insensitive 2

Therefore, the TEXTBEFORE function will return the Jurassic.

Case Insensitive 3

Example 4

If the instance_num is more than the length of the input text or equals zero, then the TEXTBEFORE function will give you the #VALUE! error.

Solution

Step 1 − Enter the formula =TEXTBEFORE(B3,"park",0,1) in the D3 cell. Here, the third argument, instance_num, contains zero value which is not allowed.

Instance Num

Therefore, the TEXTBEFORE function will return a #VALUE error.

Instance Num 1

Step 2 − In another scenario, write the formula =TEXTBEFORE(B3,"park",50,1) in the D3 cell. Here, the instance_number value is 50, greater than the length of the input string Jurassic Park.

Instance Num 2

Hence, the TEXTBEFORE function will obtain the #VALUE error.

Instance Num 3

Download Practice Sheet

You can download and use the sample data sheet to practice the TEXTBEFORE function.

Advertisements