Extract Only Numbers From Text String


Well-known Member
Dear Smartest Excelers Around,

Is there a one cell formula that could take this string in cell A1:


and extract only the numbers and deliver this


to a single cell?

The formula would have to be able to deal with all 255 ASCII characters and be copied down a column.

Ron Coderre

MrExcel MVP
Try this:

A1 containing an alphanumeric string: eg 9128ABC37DEF465

(instead of just ENTER) returns ONLY the numbers:
B1: =SUM(MID(A1,LARGE(ISNUMBER(--MID(A1,ROW($1:$25),1))*
In the above example, the formula returns: 912837465

That formula works for text up to 25 characters long.

Is that something you can work with?
Last edited:

Ron Coderre

MrExcel MVP
I played around with the formula some more...
This non-array formula seems to be working:


Active Member
Ron, is there a way to modify the formula to get the 2nd number to the right instead of the sum? The result is 37.

Ron Coderre

MrExcel MVP
Ron, is there a way to modify the formula to get the 2nd number to the right instead of the sum? The result is 37.
Apparently, my coffee has worn off...
Can you give one or more examples of source text and
the corresponding numbers to return?

Ron Coderre

MrExcel MVP
Got it! I understand...evidently, the last coffee molecule just bumped into my brain.

This formula returns the second sequence of numbers from a string in the format of: digits letters digits
B1: =LOOKUP(99^99,--("0"&MID(MID(A1,LEN(LOOKUP(10^99,--LEFT(A1,ROW($1:$25)
I'm hoping that can be shortened.

That formula returns these results:
For: 45t*&65/
result: 65

For: 9128A+BC37/E*465
result: 37

Does that help?


Well-known Member
The formula from Domenic at post 6:
works great (I changed my string to cell A2):


Ron Coderre,
This formula is beautiful (I changed my string to cell A2):


Ron, I like your formula because of its compactness and non-array non-Ctrl-Shift-Enter.
I like Domenic’s because of the robustness of the ROW(INDIRECT("1:"&LEN(A2))).
Mashing your two formulas together (in Excel 2007 only – exceeds 7 nesting rule in Excel 2003) I got:


I learn a lot from both formulas. In essence, are these the concepts of how the formula is working:

1) Extract characters with MID
2) Convert extracted characters to numbers and errors with --
3) Ask array if elements are numbers with ISNUMBER
4) Multiply array of TRUE/FALSE by position -- *ROW(INDIRECT("1:"&LEN($A$2)))
5) Organize by position with LARGE (largest to smallest including zeroes)
6) Add 1 to avoid error with MID caused by zeros from LARGE
7) Concatenate a zero to beginning of string so the 1 added to the zeros will not cause error when MID extracts numbers
8) Multiply the extracted numbers by 10^ROW(INDIRECT("1:"&LEN($A$2))) to get the correct number of zeros for each extracted number
9) Divide by 10 to deal with the fact the we had a zero concatenated to the front of the string
10) Added

Am I getting the concepts, right?


Active Member
It looks I should definitely consider upgrading to Excel 2007. Probably, exceeding 7 nested brackets. How would I make this work with Excel 2003? Can I separate it into two columns?

Ron Coderre

MrExcel MVP
As much as I loathe giving array formula solutions
(nobody I work with ever remembers to CSE them),
I think there's a certain elegance to this one:
B1: =LOOKUP(10^99,--MID(A1,MIN(IF((--ISNUMBER(--MID(A1,ROW($1:$25),1))=0)*
Does that help?

Some videos you may like

This Week's Hot Topics

  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Syntax errors
    Good Morning, Trying to compile a workbook, I keep getting a few errors. Here are the first two: [code=rich]Syntax Error: Function...