Skip to main content

Extract substring from text string in Excel

Author: Xiaoyang Last Modified: 2020-01-10

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.


Extract substring with specific number of characters from text string

In Excel, the LEFT, RIGHT and MID functions can help you to extract the substring of a specified length from left, right or middle of the text string.

  • LEFT function: to extract a substring from the left of the text string.
  • RIGHT function: to extract text from the right of the text string.
  • MID function: to extract a substring from the middle of a text string.

Extract the substring from the left of the text string:

The LEFT function can help you to extract the first x characters from the text string, the generic syntax is:

=LEFT (text, [num_chars])
  • text: the text string that you want to extract characters.
  • num_chars: the number of characters that you want to extract from the left side of the text string.

Please enter the following formula into a blank cell:

=LEFT(A2,3)

Then, drag the fill handle down to the cells that you want to apply this formula, and all first 3 characters have been extracted from the original text, see screenshot:


Extract the substring from the right of the text string:

To extract the substrings from the end of the text, please use the RIGHT function:

=RIGHT (text, [num_chars])
  • text: the text string that you want to extract characters.
  • num_chars: the number of characters that you want to extract from the right side of the text string.

For example, to extract the last 6 characters from the text string, please enter the below formula into a blank cell:

=RIGHT(A2,6)

And then, copy this formula to other cells that you need, and all 6 characters have been extracted from the right of the text, see screenshot:


Extract the substring from the middle of the text string:

To extract the substring with a specific character length from the middle of the text, the MID function can do you a favor.

=MID (text, start_num, num_chars)
  • text: the text string that you want to extract characters.
  • start_num: the location of the first character that you want to extract.
  • num_chars: the total number of characters you want to extract.

For example, to extract 3 characters which begins at the seventh character from the text string, please enter the below formula into a blank cell:

=MID(A2,7,3)

And then, drag the fill handle down to the cells to apply this formula as you need, you will get the following result:


Extract substring before or after a specific character from text string

The LEFT, RIGHT and MID functions can help you to extract the uniform substring with specific number of characters, but, sometimes, you may need to extract substring of variable length, you can create some more complex formulas to solve this job.

Extract substring before a specific character

For extracting all characters before a specific character, the generic syntax is:

=LEFT(text, SEARCH(char, text)-1)
  • text: the text string that you want to extract characters from.
  • char: the specific character to extract the substring based on.

For instance, I want to extract all characters that before the hyphen character, please apply the following formula into a blank cell:

=LEFT(A2, SEARCH("-",A2)-1)

Then drag the fill handle down to the cells that you want to apply this formula, and all characters before the hyphen have been extracted as following screenshot shown:


Explanation of the formula:
  • SEARCH("-",A2)-1: This SEARCH function is used to find the position of the hyphen character in cell A2, and subtract 1 to exclude the character itself. It is recognized as the num_chars argument of the LEFT function.
  • LEFT(A2, SEARCH("-",A2)-1): This LEFT function extracts the number of characters returned by the SEARCH function from the left side of the text in cell A2.

Extract substring after a specific character

If you want to extract the substrings after a specific character, the RIGHT, LEN, SEARCH function can help you, the generic syntax is:

=RIGHT(text,LEN(text)-SEARCH(char, text)
  • text: the text string that you want to extract characters from.
  • char: the specific character to extract the substring based on.

To extract the characters after the hyphen character, please apply the below formula:

=RIGHT(A2,LEN(A2)-SEARCH("-",A2))

And then, copy this formula to the cells that you want to use, and you will get the result as below screenshot shown:


Explanation of the formula:
  • SEARCH("-",A2): This SEARCH function is used to find the position of the hyphen character in cell A2.
  • LEN(A2)-SEARCH("-",A2): The total length of the text string returned by LEN function subtracts the number returned by SEARCH function to get the number of the characters after the specific character. This is recognized as the num_chars argument of the RIGHT function.
  • RINGT(): This RIGHT function is used to extract the number of characters from the end of the text string in cell A2.

Extract substring between two specific characters

If you need to extract the substring between two given characters, maybe the below functions can help you, the generic syntax is:

=MID(text, SEARCH(char, text)+1, SEARCH (char, text, SEARCH (char, text)+1) - SEARCH (char, text)-1)
  • text: the text string that you want to extract characters from.
  • char: the specific character to extract the substring based on.

For example, to extract the text between the two hyphens, please use this formula:

=MID(A2, SEARCH("-",A2) + 1, SEARCH("-",A2,SEARCH("-",A2)+1) - SEARCH("-",A2) - 1)

Then, drag the fill handle down to apply this formula to other cells, and you will get the result as following screenshot shown:


Explanation of the formula:
  • SEARCH("-",A2) + 1: The SEARCH function is used to return the position of the hyphen character, and add 1 means to extract the substring from the next character. It is recognized as the start_num argument of the MID function.
  • SEARCH("-",A2,SEARCH("-",A2)+1): This part of the formula is used to get the position of the second occurrence of the hyphen character.
  • SEARCH("-",A2,SEARCH("-",A2)+1) - SEARCH("-",A2) - 1): Use the position of the second hyphen character subtract the position of the first hyphen character to get the number of the characters between these two hyphen characters, then subtract 1 from the result to exclude the delimiter character. This is recognized as the num_chars argument of the MID function.
  • MID(): This MID function is used to extract the substring based on the above two arguments.

Relative functions used:

  • LEFT:
  • The LEFT function extracts string from left of the text string.
  • RIGHT:
  • The RIGHT function returns the text from right of the text string.
  • MID:
  • The MID function returns the specific characters from the middle of text string.
  • SEARCH:
  • The SEARCH function can help you to find the position of a specific character or substring from the given text

More articles:

  • Extract Last Line Of Text From A Multi-Line Cell
  • To extract the last line of text from a text string which is separated by line breaks, normally, there is no direct way for you to solve this. This article, I will introduce a formula to deal with this task in Excel.

The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates  |  Delete Blank Rows  |  Combine Columns or Cells without Losing Data  |  Round without Formula ...
Super VLookup: Multiple Criteria  |  Multiple Value  |  Across Multi-Sheets  |  Fuzzy Lookup...
Adv. Drop-down List: Easy Drop Down List  |  Dependent Drop Down List  |  Multi-select Drop Down List...
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus  |  Design View  |  Big Formula Bar  |  Workbook & Sheet Manager | Resource Library (Auto Text)  |  Date Picker  |  Combine Worksheets  |  Encrypt/Decrypt Cells  |  Send Emails by List  |  Super Filter  |  Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters ...)  |  50+ Chart Types (Gantt Chart ...)  |  40+ Practical Formulas (Calculate age based on birthday ...)  |  19 Insertion Tools (Insert QR Code, Insert Picture from Path ...)  |  12 Conversion Tools (Numbers to Words, Currency Conversion ...)  |  7 Merge & Split Tools (Advanced Combine Rows, Split Excel Cells ...)  |  ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...

Description


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, Edge and Firefox.
Comments (2)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
=RIGHT(A2,LEN(A2)-SEARCH("-",A2))
эта формула не работает, т.к. в эксель роль разделителя выполнять точка с запятой ";"
This comment was minimized by the moderator on the site
Hello, Вурдалака
This formula works well in our English language, and a semicolon may be required in other languages.
Thank you!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations