Pulling the number out of a mixed string — 123 from INV-123, a quantity from a label — is a frequent cleanup job. When the number sits after a known marker it’s a one-liner; for digits scattered anywhere, a modern array formula does it.
INV-123):
The example
Invoice codes with the number after a dash.
| A | B | |
|---|---|---|
| 1 | Code | Number |
| 2 | INV-123 | 123 |
| 3 | INV-4570 | 4570 |
| 4 | INV-88 | 88 |
The formula
The number, as a real value:
How it works
Two functions, one clear job each:
TEXTAFTER(A2, "-")returns everything to the right of the dash — the text"123".VALUE(…)converts that text into the number123, so it can be summed or compared.- No dash? Use the marker that fits —
TEXTAFTER(A2, " ")for a space, or the legacy MID/FIND approach below.
Digits scattered anywhere (like A12B3)? In Excel 365: =VALUE(TEXTJOIN("",1,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,""))) — it tests each character and keeps only the digits.
Try it: interactive demo
Type a code; see the number pulled out (after the dash, or all digits).
Variations
Legacy: number after a marker
Any version, when digits follow a known character:
Number before a marker
TEXTBEFORE grabs the left side:
All digits anywhere (365)
Keep only numeric characters:
Pitfalls & errors
#VALUE! from VALUE. The extracted text wasn’t purely numeric (an extra letter or space slipped in). Trim it, or wrap in IFERROR.
Leading zeros vanish. VALUE turns "007" into 7. If the code must stay text (an ID), skip VALUE and keep the string.
TEXTAFTER/TEXTSPLIT need Excel 365. Older versions show #NAME? — use the MID/FIND legacy formula.
Practice workbook
Frequently asked questions
How do I extract a number from text in Excel?
How do I extract digits scattered anywhere in a string?
Why does my extracted number lose leading zeros?
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