How to Extract Numbers from Text In Excel

  • Home
  • / How to Extract Numbers from Text In Excel
How to Extract Numbers from Text In Excel

Extracting numbers from text in Excel is a common task that can be useful for various data analysis and reporting purposes. Whether you are dealing with a large dataset, cleaning up data, or preparing a report, knowing how to extract numbers efficiently can save you a lot of time.This article will guide you through the step-by-step process of how to extract numbers from text in Excel, covering several methods that cater to different user needs.

Significance of Extracting Numbers from Text in Excel

In many real-world scenarios, data is often not in the ideal format for analysis. For example, you might have a list of product codes, each containing both letters and numbers, or you might receive a report where monetary values are mixed with descriptive text.

Extracting numbers from such mixed content allows you to:

  1. Perform Numerical Calculations:

Isolate numbers to conduct sums, averages, and other mathematical operations.

  1. Data Cleaning:

Prepare datasets for further analysis by separating numerical data from text.

  1. Improve Data Accuracy:

Ensure that numerical data is correctly extracted and utilized, reducing the risk of errors.

  1. Automate Processes:

Streamline repetitive tasks using Excel functions or VBA (Visual Basic for Applications) scripts.

Step-by-Step Process of Extracting Numbers from Text in Excel

Method 1: Using Excel Functions

  1. Using the `TEXTJOIN`, `MID`, `IF`, `ISNUMBER`, and `LEN` Functions

This method combines several functions to extract numbers from a text string.

  1. Define the Data Range:

Assume the text data is in cell `A1`.

  1. Create a Helper Column:

In cell `B1`, enter the following formula:

This formula works as follows:

   `INDIRECT(“1:” & LEN(A1))` creates an array of numbers from 1 to the length of the text in `A1`.

   `ROW(INDIRECT(“1:” & LEN(A1)))` generates a row number for each character in the text.

   `MID(A1, ROW(INDIRECT(“1:” & LEN(A1))), 1)` extracts each character in the text.

   `ISNUMBER(…*1)` checks if the extracted character is a number.

   `IF(ISNUMBER(…), …, “”)` retains the number if it is a number, otherwise returns an empty string.

   `TEXTJOIN(“”, TRUE, …)` concatenates all the numbers into a single string.

  1. Convert Text to Numbers:

If the result in cell `B1` is in text format and you need it in number format, use:

  1. Using the `TEXT` and `SUBSTITUTE` Functions for Fixed Format

If your text follows a fixed format where numbers and text are predictable, you can use simpler functions.

  1. Identify the Fixed Pattern:

Suppose the text in cell `A1` is always in the format “Text123Text”.

  1. Extract Numbers:

Use the following formula:

This formula replaces “Text” with an empty string, leaving only the numbers.

Method 2: Using VBA for More Complex Scenarios

For more complex text formats or if you need a more automated solution, VBA can be very effective.

  1. Open the VBA Editor:

   Press `ALT + F11` to open the VBA editor.

  Insert a new module: Right-click on any of the items in the left-hand pane and select `Insert` > `Module`.

  1. Enter the VBA Code:


This VBA function works as follows:

   `Len(Cell.Value)` gets the length of the text.

   `Mid(Cell.Value, i, 1)` extracts each character.

   `IsNumeric(Char)` checks if the character is a number.

   If the character is a number, it is concatenated to the `Output` string.

  1. Use the VBA Function in Excel:

   Return to Excel and use the new function: `=ExtractNumbers(A1)` in a cell to extract numbers from the text in cell `A1`.

Method 3: Using Power Query for Advanced Data Transformation

Power Query is a powerful tool in Excel for data transformation and extraction tasks.

  1. Load Data into Power Query:

   Select the data range and go to `Data` > `From Table/Range`.

  1. Transform Data in Power Query Editor:

   In the Power Query editor, select the column containing the text.

   Use the `Add Column` > `Custom Column` feature.

   Enter a custom formula to extract numbers. For example:

This formula extracts all characters that are numbers from the specified column.

  1. Load Transformed Data Back to Excel:

   Click `Close & Load` to load the transformed data back into Excel.


  • Extracting numbers from text in Excel can be achieved using various methods, each suited to different scenarios and user preferences.
  • Whether you prefer using built-in Excel functions, VBA for more complex tasks, or Power Query for advanced data transformation, there is a solution to fit your needs.
  • By mastering these techniques of how to extract numbers from text in Excel, you can streamline your data processing workflows and improve the accuracy and efficiency of your data analysis.

Write your comment Here