Log in  \/ 
x
or
x
x
Register  \/ 
x

or

Extract text before or after second space or comma

If you need to extract the text strings which are before or after the second or nth specific character (space or comma) from a list of cells, this article will introduce some formulas for solving this task in Excel.


Extract the text after the second or nth space or comma in Excel

In Excel, the combination of the TRIM, MID, FIND and SUBSTITUTE functions can help you to deal with this task, the generic syntax is:

=TRIM(MID(text,FIND("#",SUBSTITUTE(text," ","#",Nth))+1,255))
  • text: The text string or cell reference that you want to extract text from.
  • Nth: Represents the space or comma instance number that you want to extract text based on.

Please enter or copy the following formula into a blank cell where you want to output the result:

=TRIM(MID(A2,FIND("#",SUBSTITUTE(A2," ","#",2))+1,255))


Explanation of the formula:

SUBSTITUTE(A2," ","#",2): This BUBSTITUTE function is used to find and replace the second space character with # character in cell A2. You will get the result as this: “Insert multiple#blank rows”. This returned result is recognized as the within_text argument in FIND function.

FIND("#",SUBSTITUTE(A2," ","#",2))+1: The FIND function will get the position of the # character within the text string returned by the SUBSTITUTE function, adding 1 means to get the starting position after the second space in text, and you will get 17. The returned result will be recognized as the start_num argument in the MID function.

MID(A2,FIND("#",SUBSTITUTE(A2," ","#",2))+1,255): The MID function is used to extract 255 characters from a text string in cell A2 which start at the number of character returned by the FIND function.

doc extract after second space 04

TRIM(): This TRIM function will remove all extra spaces and only leave one between the words.


Notes:

1. If your texts are separated by comma or other delimiters, you just need to replace the space string with other separators as you need. Such as:

=TRIM(MID(A2,FIND("#",SUBSTITUTE(A2,",","#",2))+1,255))

2. To extract the text after the nth space, please change the number 2 to the number you need in the formula, for example, to extract the text after the third space, you just need to apply the following formula:

=TRIM(MID(A4,FIND("#",SUBSTITUTE(A4," ","#",3))+1,255))


Extract the text before the second or nth space or comma in Excel

To extract the text before the second or nth space or comma, the LEFT, SUBSTITUTE and FIND functions can do you a favor. The generic syntax is:

=LEFT(text,FIND("#",SUBSTITUTE(text, " " ,"#",Nth))-1)
  • text: The text string or cell reference that you want to extract text from.
  • Nth: Represents the space or comma instance number that you want to extract text based on.

Please copy or enter the below formula into a blank cell:

=LEFT(A2,FIND("#",SUBSTITUTE(A2," ","#",2))-1)

And then, drag the fill handle down to the cells that you want to apply this formula, and all the texts before the second space have been extracted as following screenshot shown


Explanation of the formula:

SUBSTITUTE(A2," ","#",2): This BUBSTITUTE function is used to find and replace the second space character with # character in cell A2. You will get the result as this: “Insert multiple#blank rows”. This returned result is recognized as the within_text argument in FIND function.

FIND("#",SUBSTITUTE(A2," ","#",2))-1: The FIND function will get the position of the # character within the text string returned by the SUBSTITUTE function, subtracting 1 to get the position before the second space character in text. And you will get 15. The returned result will be recognized as the num_chars argument in the LEFT function.

LEFT(A2,FIND("#",SUBSTITUTE(A2," ","#",2))-1): At last, the LEFT function is used to extract the leftmost 15 characters returned by the FIND function from the text string in cell A2.


Notes:

1. If your texts are separated by comma or other delimiters, you just need to replace the space string with other separators as you need. Such as:

=LEFT(A2,FIND("#",SUBSTITUTE(A2,",","#",2))-1)

2. To extract the text before the nth space, please change the number 2 to the number you need in the formula, for example, to extract the text before the third space, you just need to apply the following formula:

=LEFT(A4,FIND("#",SUBSTITUTE(A4," ","#",3))-1)


Relative functions used:

  • MID:
  • The MID function is used to find and return a specific number of characters from the middle of given text string.
  • LEFT:
  • The LEFT function extracts the given number of characters from the left side of a supplied string.
  • FIND:
  • The FIND function is used to find a string within another string, and returns the starting position of the string inside another one.
  • SUBSTITUTE:
  • The Microsoft Excel SUBSTITUTE function replaces text or characters within a text string with another text or characters.
  • TRIM:
  • The TRIM function removes all extra spaces from text string and only keeps single spaces between words.

More articles:

  • Extract Multiple Lines From A Cell
  • If you have a list of text strings which are separated by line breaks (that occurs by pressing Alt + Enter keys when entering the text), and now, you want to extract these lines of text into multiple cells as below screenshot shown. How could you solve it with a formula in Excel?
  • Extract Nth Word From Text String In Excel
  • If you have a list of text strings or sentences, now, you want to extract the specific nth word from the list as below screenshot shown. This article, I will introduce some methods for solving this job in Excel.
  • Extract Text Between Parentheses From Text String
  • If there is part of the text surrounded with the parentheses within the text string, now, you need to extract all the text strings between the parentheses as following screenshot shown. How could you solve this task in Excel quickly and easily?
  • Extract Substring From Text String In Excel
  • It may be a common task for you that you need to extract substrings from text strings, in Excel, there is not a direct function for doing this, but, with the help of the LEFT, RIGHT, MID and SEARCH functions, you can extract kinds of substrings as you need.

The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300 powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) and save 80% time for you.

  • Designed for 1500 work scenarios, helps you solve 80% Excel problems.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
  • Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
  • 30-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years.
Ribbon of Excel (with Kutools for Excel installed)

Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

  • One second to switch between dozens of open documents!
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Firefox, And New Internet Explorer.
Screen Shot of Excel (with Office Tab installed)
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.