Extract Numbers From Text In Excel

Intro

Learn how to extract numbers from text in Excel using formulas and functions. Discover methods to separate numbers from strings, including using Text to Columns, MID, and REGEX. Master Excel data manipulation and improve data analysis with these easy-to-follow steps, formulas, and expert tips.

Extracting numbers from text in Excel can be a daunting task, but with the right techniques and formulas, it can be done efficiently. In this article, we will explore the various methods to extract numbers from text in Excel, including using formulas, functions, and add-ins.

Why Extract Numbers from Text?

There are several scenarios where extracting numbers from text is necessary. For example, you may have a column of text data that contains both numbers and text, and you need to extract the numbers for analysis or calculations. Alternatively, you may have a dataset that contains text strings with embedded numbers, and you need to extract those numbers for further processing.

Method 1: Using the TEXT TO COLUMNS Feature

One of the simplest ways to extract numbers from text in Excel is to use the Text to Columns feature. This feature allows you to split text into separate columns based on a delimiter, such as a space or a comma.

To use the Text to Columns feature, follow these steps:

  1. Select the text data that you want to extract numbers from.
  2. Go to the Data tab in the ribbon.
  3. Click on the Text to Columns button.
  4. In the Text to Columns dialog box, select the delimiter that separates the text and numbers.
  5. Click on the Finish button.

Method 2: Using the LEFT and RIGHT Functions

Another way to extract numbers from text in Excel is to use the LEFT and RIGHT functions. These functions allow you to extract a specified number of characters from the left or right side of a text string.

To use the LEFT and RIGHT functions, follow these steps:

  1. Select the text data that you want to extract numbers from.
  2. In a new column, enter the formula: =LEFT(A1,LEN(A1)-FIND(" ",A1))
  3. Press Enter to apply the formula.
  4. The formula will extract the numbers from the text string.

Note: The FIND function is used to find the position of the space character in the text string. The LEN function is used to find the length of the text string.

Method 3: Using the MID Function

The MID function is another way to extract numbers from text in Excel. This function allows you to extract a specified number of characters from a text string, starting from a specified position.

To use the MID function, follow these steps:

  1. Select the text data that you want to extract numbers from.
  2. In a new column, enter the formula: =MID(A1,FIND(" ",A1)+1,LEN(A1)-FIND(" ",A1))
  3. Press Enter to apply the formula.
  4. The formula will extract the numbers from the text string.

Note: The FIND function is used to find the position of the space character in the text string. The LEN function is used to find the length of the text string.

Method 4: Using Regular Expressions

Regular expressions (regex) are a powerful way to extract numbers from text in Excel. Regex allows you to search for patterns in text data and extract the matching text.

To use regex in Excel, you need to use the VBA editor and create a user-defined function (UDF). Here is an example of a UDF that extracts numbers from text using regex:

Function ExtractNumbers(text As String) As String
    Dim regex As Object
    Set regex = CreateObject("VBScript.RegExp")
    regex.Pattern = "\d+"
    regex.Global = True
    ExtractNumbers = regex.Replace(text, "")
End Function

To use the UDF, follow these steps:

  1. Open the VBA editor by pressing Alt+F11.
  2. In the VBA editor, create a new module by clicking on Insert > Module.
  3. Paste the UDF code into the module.
  4. Save the module by clicking on File > Save.
  5. In a new column, enter the formula: =ExtractNumbers(A1)
  6. Press Enter to apply the formula.
  7. The formula will extract the numbers from the text string.

Method 5: Using the FILTERXML Function

The FILTERXML function is a new function in Excel 2019 and later versions that allows you to extract data from XML strings using XPath expressions.

To use the FILTERXML function, follow these steps:

  1. Select the text data that you want to extract numbers from.
  2. In a new column, enter the formula: =FILTERXML("<t><d>"&A1&"</d></t>","//d[number(.)]")
  3. Press Enter to apply the formula.
  4. The formula will extract the numbers from the text string.

Note: The FILTERXML function uses an XPath expression to extract the numbers from the text string.

Extract Numbers from Text

Method 6: Using the SUBSTITUTE and VALUE Functions

The SUBSTITUTE and VALUE functions can be used together to extract numbers from text in Excel.

To use the SUBSTITUTE and VALUE functions, follow these steps:

  1. Select the text data that you want to extract numbers from.
  2. In a new column, enter the formula: =VALUE(SUBSTITUTE(A1,"abc",""))
  3. Press Enter to apply the formula.
  4. The formula will extract the numbers from the text string.

Note: The SUBSTITUTE function replaces the text "abc" with an empty string, and the VALUE function converts the resulting string to a number.

Method 7: Using the Flash Fill Feature

The Flash Fill feature is a new feature in Excel 2013 and later versions that allows you to automatically fill a range of cells with a formula.

To use the Flash Fill feature, follow these steps:

  1. Select the text data that you want to extract numbers from.
  2. Go to the Data tab in the ribbon.
  3. Click on the Flash Fill button.
  4. In the Flash Fill dialog box, select the range of cells that you want to fill.
  5. Click on the OK button.
  6. The Flash Fill feature will automatically fill the range of cells with a formula that extracts the numbers from the text string.
Flash Fill Feature

Gallery of Extract Numbers from Text

Conclusion

Extracting numbers from text in Excel can be a challenging task, but with the right techniques and formulas, it can be done efficiently. In this article, we have explored the various methods to extract numbers from text in Excel, including using formulas, functions, and add-ins. Whether you are a beginner or an advanced user, this article has provided you with the knowledge and skills to extract numbers from text in Excel.

Jonny Richards

Love Minecraft, my world is there. At VALPO, you can save as a template and then reuse that template wherever you want.