Excel has a set of TEXT Functions that can do wonders. You can do all kinds of text slice and dice operations using these functions.
One of the common tasks for people working with text data is to extract a substring in Excel (i.e., get psrt of the text from a cell).
Unfortunately, there is no substring function in Excel that can do this easily. However, this could still be done using text formulas as well as some other in-built Excel features.
Let’s first have a look at some of the text functions we will be using in this tutorial.
Excel has a range of text functions that would make it really easy to extract a substring from the original text in Excel. Here are the Excel Text functions that we will use in this tutorial:
When working with text strings in Excel, you’ll often need to extract and manipulate substrings – whether it’s cleaning up data, parsing out parts of text, or performing text analysis. Luckily, Excel provides several straightforward ways to extract substrings and characters from strings.
This guide will walk through the key methods to extract substrings and text using Excel functions and features like LEFT, RIGHT, MID, FIND, SEARCH, and Flash Fill. Follow along to learn how to master substring extraction in Excel.
Why Extract Substrings in Excel?
Here are some common use cases for extracting substrings in Excel:
-
Data cleaning – Extracting consistent substrings from long strings can help clean up and standardize messy data For example, parsing out ZIP codes or ID numbers
-
Text parsing – Breaking down strings into substrings enables analyzing the component parts. Like parsing names into first/last or extracting domains from URLs.
-
Text manipulation – Grabbing substrings allows you to reorder, replace or modify components of larger strings
-
Key field extraction – Identifying and extracting substrings from critical fields like product codes helps with categorization.
-
String aggregation – Combining substrings together can construct new concatenated strings for reporting.
Whether you need to clean up data, dissect text, or extract key parts of strings, Excel provides easy ways to get the substrings you need.
Excel Substring Functions
Excel includes several functions that can extract substrings by specifying a starting position and number of characters to return.
LEFT, RIGHT and MID
The LEFT, RIGHT and MID functions are the key substring extraction functions.
- LEFT – Returns characters from the start of a string
- RIGHT – Returns characters from the end of a string
- MID – Returns characters from the middle of a string
The basic syntax is:
=LEFT(text, num_chars)
=RIGHT(text, num_chars)
=MID(text, start_num, num_chars)
For example, =LEFT(A2, 5)
would return the first 5 characters in cell A2.
You can nest these together like =LEFT(RIGHT(A2, 10), 3)
to extract substrings from substrings.
FIND and SEARCH
The FIND and SEARCH functions locate one string within another string and return its starting position. This enables extracting substrings based on delimiters.
For example, if cell A2 contained “Excel_Tips.docx”, then:
=LEFT(A2,FIND("_",A2)-1)
would extract “Excel”
=RIGHT(A2,FIND(".docx",A2)-1)
would extract “Tips”
This approach is powerful for extracting components of strings with consistent delimiters like underscores, periods, commas, etc.
Using MID and FIND
A common use pattern is combining MID and FIND to extract a substring based on delimiters:
=MID(text, FIND(start_delimiter, text) + length(start_delimiter), FIND(end_delimiter, text) - FIND(start_delimiter, text) - length(start_delimiter))
It first uses FIND to locate the starting delimiter, then captures everything between the start and end delimiter based on their positions.
For example, to extract the domain from email addresses:
=MID(A2,FIND("@",A2)+1,FIND(".",A2)-FIND("@",A2)-1)
This formula extracts the text between the @ and . in the email string.
Additional Substring Functions
Here are a few more Excel functions that can help extract characters or substrings:
- TRIM – Remove leading, trailing and excess spaces from text
- CLEAN – Remove non-printable characters like tabs and page breaks
- SUBSTITUTE – Replace or remove substrings
- REPLACE – Replace characters within a substring
- REPT – Repeat strings to a specified length
Using Flash Fill
Excel’s Flash Fill feature can automatically extract substrings and parse text based on examples, saving you from writing formulas.
To use Flash Fill:
-
Enter examples of the extracted text into adjacent columns
-
Select the columns
-
Go to Data > Flash Fill
-
Excel will automatically fill down the extracted text
Flash Fill uses pattern recognition to parse and extract substrings intelligently. It’s a quick way to split text without formulas.
Text to Columns
Another simple option: use the Text to Columns wizard (Data tab) to split text into multiple columns by a delimiter like a comma or space.
This can instantly separate string components into discrete columns. Useful for parsing structured text like CSV data.
VBA Substrings
You can also leverage VBA functions to extract substrings in Excel macros:
- Left – Same as LEFT worksheet function
- Right – Same as RIGHT worksheet function
- Mid – Same as MID worksheet function
- InStr – Find position of substring
- Split – Split string into array by delimiter
VBA provides added flexibility for substring manipulation.
Extracting Substrings with Power Query
In Power Query, you can extract substrings from text columns using:
- Text.Start – Extract start of string
- Text.End – Extract end of string
- Text.Middle – Extract middle substring
- Text.BeforeDelimiter – Extract before delimiter
- Text.AfterDelimiter – Extract after delimiter
- Text.BetweenDelimiters – Extract between two delimiters
Power Query offers robust text parsing capabilities to integrate, cleanse, and transform data from multiple sources.
Summary
Excel has all the capabilities needed for flexible substring extraction. The key takeaways are:
-
LEFT, RIGHT and MID extract a specified number of characters from the start, end or middle of text.
-
FIND and SEARCH identify delimiter positions required by functions like MID.
-
Flash Fill can automatically parse and extract substrings with pattern recognition.
-
Text to Columns separates text into columns by delimiters.
-
Power Query provides advanced text parsing transformations.
With these tools, you can cleanly extract the substrings, characters and text components needed for your raw data cleansing, text manipulation and analytics needs.
So next time you need to slice and dice text in Excel, grab just the substring you want!
Using Text to Columns to Extract a Substring in Excel
Using functions to extract a substring in Excel has the advantage of being dynamic. If you change the original text, the formula would automatically update the results.
If this is something you may not need, then using the Text to Columns feature could be a quick and easy way to split the text into substrings based on specified markers.
Here is how to do this:
- Select the cells where you have the text.
- Go to Data –> Data Tools –> Text to Columns.
- In the Text to Column Wizard Step 1, select Delimited and press Next.
- In Step 2, check the Other option and enter @ in the box right to it. This will be our delimiter that Excel would use to split the text into substrings. You can see the Data preview below. Click on Next.
- In Step 3, General setting works fine in this case. You can however, choose a different format if you are splitting numbers/dates. By default, the destination cell is where you have the original data. If you want to keep the original data intact, change this to some other cell.
- Click on Finish.
This will instantly give you two sets of substrings for each email id used in this example.
If you want to further split the text (for example, split batman.com to batman and com), repeat the same process with it.
Extract a Substring in Excel Using Functions
Suppose you have a dataset as shown below:
These are some random (but superhero-ish) email ids (except mine), and in the examples below, I’ll show you how to extract the username and domain name using the Text functions in Excel.
Extract a substring in Excel with a variable starting and ending position (2m)
How to extract a substring from the original text in Excel?
Excel has a range of text functions that would make it really easy to extract a substring from the original text in Excel. Here are the Excel Text functions that we will use in this tutorial: RIGHT function: Extracts the specified numbers of characters from the right of the text string.
How do I extract a substring from a text string?
Depending on where you want to start extraction, use one of these formulas: LEFT function – to extract a substring from the left. RIGHT function – to extract text from the right. MID function – to extract a substring from the middle of a text string, starting at the point you specify.
How do I find a substring in Excel?
The FIND function in Excel helps you locate specific characters within a text string. It returns the position of the character you’re searching for, which you can then use in conjunction with other functions like LEFT, RIGHT, or MID to extract substrings. How can I get a substring from a cell using an offset?
Is there a substring function in Excel?
For example, if you type something like “AA-111” in a cell, you’d call it an alphanumeric string, and any part of the string, say “AA”, would be a substring. Although there is no such thing as Substring function in Excel, there exist three Text functions (LEFT, RIGHT, and MID) to extract a substring of a given length.