How to Extract Number from Text String in Excel


This post will guide you how to extract number from a given test string in Excel. How do I extract all numbers from string using a formula in Excel. How to get all number from a given test string using user defined function in Excel.

Assuming that you have a list of data in range B1:B5, in which contain text string values, and you want to eextract all numbers from each cell in which contain letters and numbers. In other words, you wish to remove all letters from those text strings. And this post will show you two methods to accomplish it.

1. Extract Number from String with Formula

If you want to extract numbers from a range of cells that contain text string values, you need to use an array formula based on the SUM function, MID function, LARGE function, INDEX function, ISNUBER function and the ROW function to extract all numbers from one cell that contain text string values. Like this:


You need to type this formula into a blank cell and press Ctrl + Shift +Enter key on your keyboard to change the current common formula as Array formula.  Then drag the AutoFill handle down to other cells.

extract number from text string1

Note: B1 is the cell that you want to extract numbers from.

2. Extract Number from String with User Defined Function

You can also use an VBA code to define a User defined function to accomplish the same result of extracting all numbers from text string in Excel. Just do the following steps:

Step1# open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

Step2#  then the “Visual Basic Editor” window will appear.

Step3# click “Insert” ->”Module” to create a new module.

convert column number to letter3

Step4# paste the below VBA code into the code window. Then clicking “Save” button.

Function extractNumbers(Txt As String) As String
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "\D"
extractNumbers = .Replace(Txt, "")
End With
End Function
extract number from text string2

#5 back to the current worksheet, then type the following formula in a blank cell, and then press Enter key. And drag the AutoFill Handle over to other cells.

extract number from text string3

3. Video: Extract Number from String

This Excel video tutorial, where we’ll explore two effective methods to extract numbers from text strings. In this session, we’ll dive into a formula-based approach using the SUM function and the VBA code method.

4. Related Functions

  • Excel SUM function
    The Excel SUM function will adds all numbers in a range of cells and returns the sum of these values. You can add individual values, cell references or ranges in excel.The syntax of the SUM function is as below:= SUM(number1,[number2],…)…
  • Excel INDEX function
    The Excel INDEX function returns a value from a table based on the index (row number and column number)The INDEX function is a build-in function in Microsoft Excel and it is categorized as a Lookup and Reference Function.The syntax of the INDEX function is as below:= INDEX (array, row_num,[column_num])…
  • Excel ISNUMBER function
    The Excel ISNUMBER function returns TRUE if the value in a cell is a numeric value, otherwise it will return FALSE.The syntax of the ISNUMBER function is as below:= ISNUMBER (value)…
  • Excel ROW function
    The Excel ROW function returns the row number of a cell reference.The ROW function is a build-in function in Microsoft Excel and it is categorized as a Lookup and Reference Function.The syntax of the ROW function is as below:= ROW ([reference])….
  • Excel MID function
    The Excel MID function returns a substring from a text string at the position that you specify.The syntax of the MID function is as below:= MID (text, start_num, num_chars)…
  • Excel LARGE function
    The Excel LARGE function returns the largest numeric value from the numbers that you provided. Or returns the largest value in the array. The syntax of the LARGE function is as below:= LARGE (array,nth)…

Leave a Reply