Excel Formulas to Extract Only Numbers From Mixed Text Strings

📅 Apr 06, 2026 📝 Sarah Miller

Extracting clean numbers from database dumps containing mixed alphanumeric strings is a notoriously tedious task for data analysts. While standard text-manipulation functions like MID, FIND, or SUBSTITUTE offer basic filtering, they often fail when handling unpredictable formats. Deploying an advanced, nested array formula grants you immediate, automated data refinement, bypassing hours of manual cleanup. As a critical educational stipulation, please note that these advanced formulas require Excel 365 or Excel 2021 to support dynamic arrays. This methodology is highly effective for cleansing real-world datasets, such as extracting quantities from mixed SKU codes and part numbers. Below, we will detail the exact formula configurations and step-by-step logic to streamline your data processing.

Excel Formulas to Extract Only Numbers From Mixed Text Strings

Data cleaning is one of the most common yet time-consuming tasks in Excel. Quite often, you might import or copy data from external databases, PDF files, or web scraping tools, only to find that your numbers are trapped inside a messy mix of text, symbols, and spaces. For example, a column of product codes might look like "ID-9482-TX", or a list of prices might appear as "$1,250.50 USD".

If you need to perform calculations, sort the data, or use it in financial models, you must first extract only the numeric digits. In this guide, we will explore several powerful ways to trim non-numeric characters from mixed strings in Excel, ranging from modern dynamic array formulas to classic VBA and Power Query solutions.

Method 1: The Modern Excel 365 Formula (Dynamic Arrays)

If you are using Excel 365 or Excel 2021, you have access to powerful dynamic array functions like SEQUENCE, FILTER, and LET. This allows us to write a clean, elegant formula that extracts numbers without relying on complex, nested legacy functions.

The Formula

=LET(
    text, A2,
    char_list, MID(text, SEQUENCE(LEN(text)), 1),
    is_num, ISNUMBER(VALUE(char_list)),
    TEXTJOIN("", TRUE, IF(is_num, char_list, ""))
)

How It Works

The LET function allows us to define variables within our formula, making it highly readable and efficient. Here is the step-by-step breakdown of how this formula strips out non-numeric characters:

  • text, A2: We define our target cell (in this case, A2) as the variable text.
  • SEQUENCE(LEN(text)): The LEN function counts the number of characters in the string. SEQUENCE then generates a vertical array of numbers from 1 to that length. For example, if the text is "A5B", it generates {1; 2; 3}.
  • MID(text, ..., 1): The MID function extracts one character at a time based on our sequence array, effectively breaking the string down into an array of individual characters: {"A"; "5"; "B"}.
  • ISNUMBER(VALUE(char_list)): We try to convert each individual character into a number using VALUE. Non-numeric characters like "A" and "B" will return an error (#VALUE!), while "5" successfully converts to the number 5. ISNUMBER checks this conversion, returning an array of TRUE/FALSE values: {FALSE; TRUE; FALSE}.
  • IF(is_num, char_list, ""): This filters our array, keeping only the original characters that evaluated to TRUE (the numbers) and replacing everything else with an empty string ("").
  • TEXTJOIN("", TRUE, ...): Finally, TEXTJOIN merges the filtered array back together, ignoring empty cells. The result is a clean string containing only numbers: "5".

Method 2: The Legacy Formula (Excel 2019 and Older)

If you are working in an older version of Excel that does not support dynamic arrays or the LET function, you can still extract numbers using an array formula. This approach relies on a combination of TEXTJOIN, MID, ROW, INDIRECT, and LEN.

The Formula

=TEXTJOIN("", TRUE, IFERROR(MID(A2, ROW(INDIRECT("1:"&LEN(A2))), 1)*1, ""))

Note: If you are using Excel 2016 or older, you must press Ctrl + Shift + Enter after typing this formula to enter it as an array formula. When done correctly, Excel will wrap the formula in curly braces { }.

How It Works

Since older versions of Excel lack the SEQUENCE function, we construct an array of numbers using ROW(INDIRECT("1:"&LEN(A2))). This creates a virtual list of numbers from 1 to the length of your string. We then multiply the extracted characters by 1 (MID(...) * 1). If the character is a number, the multiplication succeeds; if it is a letter, it throws an error. The IFERROR function catches these errors and replaces them with blank strings, leaving only the digits to be joined together by TEXTJOIN.

Method 3: Retaining Decimals and Negative Signs

The formulas above strip away all non-numeric characters, which means punctuation like decimal points (.) and negative signs (-) are also removed. If you are dealing with financial or scientific figures (e.g., converting "approx. -45.67m" to "-45.67"), you need to modify the logic to permit these specific symbols.

The Advanced Formula

=LET(
    text, A2,
    chars, MID(text, SEQUENCE(LEN(text)), 1),
    allowed, {"0","1","2","3","4","5","6","7","8","9",".","-"},
    filtered, IF(ISNUMBER(MATCH(chars, allowed, 0)), chars, ""),
    TEXTJOIN("", TRUE, filtered)
)

In this variation, we define an array of allowed characters. Instead of checking if a character can be converted to a number, we use MATCH to see if the character exists in our allowed list. This keeps your decimals and negative signs intact while discarding letters and other symbols.

Method 4: Using Power Query (Best for Large Datasets)

If you are processing tens of thousands of rows of data, complex array formulas can slow down your workbook. Excel's Power Query (Get & Transform) tool is highly optimized for this kind of ETL (Extract, Transform, Load) task.

Step-by-Step Power Query Guide

  1. Select your data table and go to the Data tab, then click From Sheet (or From Table/Range).
  2. Once the Power Query Editor opens, go to the Add Column tab and click on Custom Column.
  3. Name your new column (e.g., Clean_Numbers).
  4. In the formula box, enter the following Power Query M formula:
    Text.Select([YourColumnName], {"0".."9"})
    (Make sure to replace [YourColumnName] with the actual name of your column by double-clicking it from the list on the right).
  5. If you want to keep decimals and negative signs as well, use this formula instead:
    Text.Select([YourColumnName], {"0".."9", ".", "-"})
  6. Click OK. Go to the Home tab, click Close & Load, and your cleaned data will be outputted to a fresh worksheet.

Method 5: VBA (User-Defined Function)

If you want a simple, reusable formula that you can use across your workbook without typing long formulas, you can create a custom User-Defined Function (UDF) using VBA.

The VBA Code

Function ExtractNumbers(Txt As String) As String
    Dim i As Integer
    Dim Result As String
    Result = ""
    For i = 1 To Len(Txt)
        If Mid(Txt, i, 1) Like "[0-9]" Then
            Result = Result & Mid(Txt, i, 1)
        End If
    Next i
    ExtractNumbers = Result
End Function

How to Install and Use It

  1. Press Alt + F11 to open the VBA Editor.
  2. Click Insert > Module.
  3. Paste the code above into the module window.
  4. Close the VBA Editor. Save your workbook as an Excel Macro-Enabled Workbook (.xlsm).
  5. Now, you can use your custom function in any cell like a regular Excel formula:
    =ExtractNumbers(A2)

Method Comparison: Which Should You Use?

Depending on your Excel version, technical comfort level, and database size, one method may be superior to the others. Refer to the table below to decide which option is best for your current workflow:

Method Excel Compatibility Dynamic / Auto-updates Best For
LET & SEQUENCE Formula Office 365 / Excel 2021+ Yes Quick, modern formula setup with no macro warnings.
Legacy Array Formula Excel 2019 and older Yes Older environments where macros/VBA are blocked.
Power Query Excel 2010+ (via Add-in) / 2016+ Manual Refresh Large enterprise datasets and repetitive data imports.
VBA User-Defined Function Excel Desktop (All versions) Yes Clean workbook appearance with short, custom formulas.

Conclusion

Extracting numbers from mixed text strings no longer requires frustrating manual entry or error-prone Flash Fill operations. By leveraging the advanced text manipulation features of modern Excel-such as LET arrays, Power Query's Text.Select, or VBA scripts-you can automate your data-cleaning processes and focus on building robust, insightful spreadsheets.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.