The second formula is significantly more complex and only makes sense if you don’t have TEXTBEFORE.

This formula is a great example of hownew functionsin Excel completely change how problems are solved.

The traditional formula is much more complex than the modern formula.

Customized formula to remove the last two words separated by hyphens

This argument is optional and defaults to 1.

This is why we get “Bob” when we don’t provide a value forinstance_num.

TRIM makes sure there is just one space between words and removes any leading or trailing spaces.

Customized formula to remove the last two words separated by hyphens

The “trimmed” text is returned directly to TEXTBEFORE as thetextargument.

The TEXTBEFORE function then returns all text before the last word, effectively removing the last word.

We can also easily change the delimiter used to separate words.

Customized formula to remove the last two words separated by hyphens

The challenge is to figure out where the last word begins and set a marker before the last word.

Then, we can locate the marker with FIND and extract everything up to that point.

The formula is convoluted, but the steps are simple.

Customized formula to remove the last two words separated by hyphens

you could use any character you like, so long as it doesn’t appear in the source text.

The result, 33, is returned to the MID function as thenum_charsargument.

We are finally ready to extract text.

Customized formula to remove the last two words separated by hyphens

This formula is a great example of hownew functionsin Excel completely change how tricky problems are solved.

The traditional formula is much more complex and much less transparent than the TEXTBEFORE solution.

Customizing the traditional formula

The same formula structure can be used with a different delimiter.

Excel formula: Remove text by position

For example, =MID(“apple”,2,3) returns “ppl”.

When the text is not found, FIND returns a #VALUE error.

SUBSTITUTE Function

The Excel SUBSTITUTE function replaces text in a given string by matching.

Excel formula: Remove text by variable position

LEN will also count characters in numbers, but number formatting is not included.

Excel TEXTBEFORE function

Excel formula: Remove characters from right

Excel TEXTBEFORE function

Excel TRIM function

Excel MID function

Excel FIND function

Excel SUBSTITUTE function

Excel LEN function

Article image

Customized formula to remove the last two words separated by hyphens