← All how-to recipes

How to extract numbers from text in a cell

✓ Verified in LibreOffice 25.8.7.3

Pull just the digits out of a cell that mixes text and numbers, like an order code or address.

The formula

AppFormulaNotes
Excel=TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,""))Excel 365/2021 (needs SEQUENCE + TEXTJOIN).
Google Sheets=REGEXREPLACE(A2,"[^0-9]","")Sheets has REGEXREPLACE, the cleanest way. The Excel formula also works.
LibreOffice Calc=TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,""))Works in LibreOffice 25.8+ (SEQUENCE arrived in 24.8).

How it works

SEQUENCE(LEN(A2)) generates one index per character, MID splits the text into single characters, multiplying by 1 turns digits into numbers and everything else into an error, IFERROR blanks the errors, and TEXTJOIN glues the surviving digits back together. "Order #4092 (qty 15)" becomes "409215". The result is text; wrap the whole thing in VALUE() if you need a real number. In Google Sheets, REGEXREPLACE(A2,"[^0-9]","") does the same job in one step.

Verified, not just documented

We ran =TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,"")) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 409215 — exactly the expected result. Every formula here is confirmed by actually executing it.