Extract Numbers from Text in Excel

Excel Formulas › Data Cleaning

All versions

Need to pull the digits out of labels like “Order #1024” or “Qty: 36 units”? One formula walks every character, keeps the numbers, drops everything else, and returns a real number you can sum or sort.


Quick formula: Walk each character, keep the digits, and join them back into a number:
=TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,""))*1

SEQUENCE visits every character position; digits survive, letters and symbols become blanks, and the final *1 turns the leftover text back into a number.

Functions used (tap for the full reference guide):

The example

A column of messy labels, each with one number buried in text. You want just the number.

AB
1Raw textNumber
2Order #1024 (large)1024
3SKU-00857857
4Qty: 36 units36
5Weight 12 kg12

The formula

The same formula handles each row — it reads the cell one character at a time:

=TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,""))*1 // keeps digits, drops the rest

How it works

Working from the inside out:

  1. SEQUENCE(LEN(A2)) lists the position of every character: 1, 2, 3, … to the end of the text.
  2. MID(A2, …, 1) pulls the single character sitting at each of those positions.
  3. Multiplying each character by 1 turns digits into numbers; letters and symbols throw an error, which IFERROR swaps for a blank.
  4. TEXTJOIN glues the surviving digits back together, and the final *1 converts that text into a real number.

Want to keep the digits as text (to preserve leading zeros like 00857)? Drop the final *1.

Try it: interactive demo

Interactive

Type any messy text — the digits are extracted into a number live.

Variations

Works in any Excel (no SEQUENCE)

Older Excel has no SEQUENCE. Swap in ROW(INDIRECT(...)) and confirm with Ctrl+Shift+Enter so it runs as an array formula.

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

Grab just the first number

If a cell has several numbers and you only want the first run of digits, REGEXEXTRACT is cleanest in Excel 365.

=VALUE(REGEXEXTRACT(A2,"\d+"))

Pitfalls & errors

If a cell holds more than one number (e.g. Room 12, Floor 3), this joins every digit into one value (123). Pull each number separately if that matters.

Turning the result into a number drops leading zeros — 00857 becomes 857. Remove the final *1 to keep it as text.

No digits at all makes the closing *1 return #VALUE!. Wrap the whole formula in IFERROR(…,"") to leave those cells blank.

Practice workbook

📊
Download the free Extract Numbers from a Text String practice workbook
Edit the yellow Raw text cells; the Number column re-extracts every digit. (Leading zeros drop once the result is a number.)

Frequently asked questions

How do I keep leading zeros?
Remove the final *1 so the result stays text. =TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,"")) returns 00857 as text instead of 857.
What if the cell has two separate numbers?
This formula joins every digit it finds, so 'Room 12, Floor 3' becomes 123. To pull them apart, use REGEXEXTRACT or split the text on its delimiter first.
Does this work in Excel 2019 or earlier?
Yes — use the ROW(INDIRECT(...)) version and confirm it with Ctrl+Shift+Enter. SEQUENCE itself needs Excel 365 or 2021.
How do I include a decimal point?
Keep characters where ISNUMBER(...) is true OR the character is a period, then wrap the joined result in VALUE to get a real decimal number.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Clean Currency Text to a Number · Extract Text with REGEXEXTRACT · Split a Full Name into First and Last

Function references: TEXTJOINMIDSEQUENCEIFERROR