Intro
Extract numbers from strings in Excel using formulas and functions like REGEX, FILTERXML, and TEXT TO COLUMNS, with step-by-step guides and examples for data extraction and manipulation.
Extracting numbers from a string in Excel can be a useful skill, especially when working with datasets that contain a mix of numerical and textual data. This process can help in cleaning up data, performing calculations, or analyzing specific parts of the data. Excel provides several functions and methods to achieve this, including the use of formulas, regular expressions (with VBA), and the Text to Columns feature. Here, we'll explore some of the most common and efficient ways to extract numbers from strings in Excel.
The importance of extracting numbers from strings cannot be overstated. In many professional settings, such as data analysis, accounting, and research, being able to quickly and accurately extract numerical data from text is crucial. It saves time, reduces the likelihood of human error, and enables the efficient processing of large datasets. Moreover, understanding how to manipulate text and extract specific information can significantly enhance one's productivity and skill set in Excel.
For those who are new to Excel or have limited experience with its advanced functions, extracting numbers from strings might seem like a daunting task. However, with the right guidance and practice, anyone can master this skill. Excel's versatility and the wide range of functions it offers make it an ideal tool for data manipulation and analysis. Whether you're working with simple strings or complex datasets, Excel has the tools you need to extract numbers efficiently.
Using Formulas to Extract Numbers

One of the most straightforward methods to extract numbers from a string in Excel is by using formulas. Excel offers several text functions that can be combined to achieve this, such as TEXT
, VALUE
, MID
, RIGHT
, LEFT
, and LEN
. For example, if you have a string in cell A1 and you want to extract a number from it, you might use a combination of these functions.
- Using the
MID
function: If you know the position of the number within the string, you can use theMID
function to extract it. The syntax isMID(text, start_num, num_chars)
, wheretext
is the string,start_num
is the position of the first character you want to extract, andnum_chars
is the number of characters you want to extract. - Using the
RIGHT
orLEFT
function: If the number is always at the beginning or end of the string, you can use theRIGHT
orLEFT
function, respectively. For example,=VALUE(RIGHT(A1,4))
extracts the last 4 characters from cell A1 and converts them into a number.
Regular Expressions (VBA)

For more complex extractions, regular expressions (regex) can be incredibly powerful. However, using regex in Excel requires enabling the Visual Basic for Applications (VBA) editor and possibly adding a reference to the Microsoft VBScript Regular Expressions library.
- Open the VBA editor by pressing
Alt + F11
or navigating to Developer > Visual Basic. - In the VBA editor, go to Tools > References and check if "Microsoft VBScript Regular Expressions 1.0" is listed. If not, check it.
- You can then use regex patterns in your VBA code to extract numbers from strings.
Example VBA function:
Function ExtractNumber(str As String) As String
Dim regEx As New RegExp
regEx.Pattern = "\d+" ' Matches one or more digits
regEx.Global = True
If regEx.Test(str) Then
ExtractNumber = regEx.Execute(str)(0).Value
Else
ExtractNumber = ""
End If
End Function
This function can be used in a cell like any other Excel function: =ExtractNumber(A1)
.
Text to Columns Feature

For simpler cases, Excel's built-in Text to Columns feature can also be used to separate numbers from text, especially if the number is consistently separated from the text by a specific character, like a space, comma, or dash.
- Select the cell or range of cells containing the text you want to split.
- Go to the Data tab on the Ribbon.
- Click on Text to Columns.
- Choose Delimited Text and click Next.
- Select the delimiter that separates the number from the text and click Next.
- Choose the format for each column and click Finish.
Power Query

Power Query, available in Excel 2010 and later versions, offers another powerful way to extract numbers from strings. You can use the Text
functions within Power Query to manipulate strings, including extracting numbers.
- Select the column containing the strings.
- Go to the Data tab and click on From Table/Range to open Power Query.
- In the Power Query Editor, you can use the
Text
functions to extract numbers. For example, you might use theText.Select
function to select digits.
Example Power Query formula:
= Table.TransformColumns(#"Previous Step", {{"Your Column", each Text.Select(_, {"0".."9"})}})
Replace "Your Column"
with the name of your column.
Practical Examples and Statistical Data

Let's consider a practical example where we have a list of product codes in the format "ABC123", and we want to extract the numbers to use in a calculation.
- Using Formulas: If the product codes are in column A, you could use the formula
=VALUE(RIGHT(A1,3))
in another column to extract the numbers, assuming the numbers are always 3 digits long and at the end of the code. - Using VBA: You could write a VBA script to loop through each cell in column A, extract the number using a regex pattern, and output the result in another column.
In terms of statistical data, being able to extract numbers from strings can significantly enhance data analysis capabilities. For instance, extracting numbers from customer feedback can help in sentiment analysis or in calculating the average rating given by customers.
Gallery of Excel Functions
Excel Functions Image Gallery










How do I extract numbers from a string in Excel using formulas?
+You can use a combination of Excel's text functions such as `MID`, `RIGHT`, `LEFT`, and `VALUE` to extract numbers from strings. For example, `=VALUE(RIGHT(A1,4))` extracts the last 4 characters from cell A1 and converts them into a number.
Can I use VBA to extract numbers from strings in Excel?
+Yes, VBA can be used with regular expressions to extract numbers from strings in Excel. This method is particularly useful for complex extractions.
How does the Text to Columns feature help in extracting numbers from strings?
+The Text to Columns feature can separate numbers from text if they are consistently separated by a specific character. It's a straightforward method for simple cases.
In conclusion, extracting numbers from strings in Excel is a valuable skill that can be achieved through various methods, including the use of formulas, VBA with regular expressions, the Text to Columns feature, and Power Query. Each method has its own advantages and is suited for different types of data and extraction requirements. By mastering these techniques, users can efficiently manipulate and analyze their data, leading to better insights and decision-making. We encourage you to practice these methods and explore further to become proficient in extracting numbers from strings in Excel. If you have any questions or would like to share your experiences with extracting numbers from strings, please feel free to comment below.