How to extract numbers from mixed alphanumeric text strings in Excel?
This tutorial provides three methods to help extracting numbers from mixed alphanumberic text string in Excel.
Extract numbers from mixed alphanumeric text strings with formula
Extract numbers from mixed alphanumeric text strings with VBA code
Easily extract numbers from mixed alphanumeric text strings with an amazing tool
You can apply the below formula to extract numbers from anywhere in a text string in Excel.
1. Select a blank cell to output the extracted numbers, enter the below formula into it and press the Enter key. Then drag the AutoFill Handle down to apply the formula to other cells.
Note: In the formula, A1 is the cell that contians the text string you want to extract numbers. Please change it based on your needs.
Then numbers are extracted from anywhere in a text string in specified cells as the above screenshot shown.
The following VBA code can help you remove all nonnumeric characters from specified range and keep only numbers in cells. Please do as follows.
Note: As the code excecutes the original range directly, please keep a copy of the original range in case of losing data.
1. Press Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Insert > Module. Then copy and paste the below VBA code into the Module window.
VBA code: remove all nonnumeric characters from cells
'Updated by Extendoffice 20210125
Dim xRegEx As Object
Dim xRg As Range
Dim xCell As Range
Dim xTxt As String
On Error Resume Next
xTxt = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Pease select range:", "Kutools for Excel", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub
Set xRegEx = CreateObject("VBScript.RegExp")
.Pattern = "\D+"
.IgnoreCase = True
.Global = True
xRg.NumberFormat = "@"
For Each xCell In xRg
xCell.Value = xRegEx.Replace(xCell.Value, "")
Set xRegEx = Nothing
3. Press the F5 key to run the code. Then a Kutools for Excel dialog box pops up, please select the range that contains the mixed alphanumeric text strings you will keep only the numbers, and click the OK button.
Now all nonnumeric characters in selected range have been removed immediately, and only the numbers kept. See screenshot:
This section recommends the Extract Text utility of Kutools for Excel. With this utility, extracting numbers from a text string can be easy to handle.
Before applying Kutools for Excel, please download and install it firstly.
1. Click Kutools > Text > Extract Text to enable the feature.
2. In the Extract Text dialog box, please do the below settings.
Note: Check the Insert as a formula box in the bottom left corner of the dialog will insert the result as formula into the result cells. When the value of the referenced cell changes, the result will update automatically.
3. In the Extract Text dialog box, select a blank cell to output the extracted text, and then click OK.
Then numbers from any position in a text string are extracted. See screenshot:
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!