FormulaCraft

How to extract every number from a text string in Excel and Google Sheets

Topic:Text manipulation

Heads up: Excel and Google Sheets do this differently.

Excel
=IFERROR(VALUE(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",100)),(SEQUENCE(LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1)-1)*100+1,100))),"")
Google Sheets
=IFERROR(REGEXEXTRACT(A2, "(\d+(?:\.\d+)?)"), "")

Verified example

Computed by a real spreadsheet engine on the sample data below.

Text
Order 42 shipped 3 items
Temperature: 98.6 degrees
Ref 1001 batch 7
Price $12.50 qty 4

=IFERROR(VALUE(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",100)),(SEQUENCE(LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1)-1)*100+1,100))),"")

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1In Google Sheets, enter =IFERROR(REGEXEXTRACT(A2, "(\d+(?:\.\d+)?)"), "") in B2 to extract the first integer or decimal from A2.
  2. 2For all numbers in Sheets, wrap in ARRAYFORMULA or use =REGEXEXTRACT(A2, "(\d+(?:\.\d+)?)") — Sheets returns the first match by default; wrap in a helper column with successive REGEXREPLACE to strip already-found matches for additional numbers.
  3. 3In Excel 365, the SUBSTITUTE + REPT approach space-pads around each word, then MID extracts 100-char chunks; VALUE converts numeric chunks and IFERROR suppresses text chunks.
  4. 4For a simpler Excel approach, use Power Query: Data → Get Data → From Table, then add a Custom Column with Text.Select([Column], {"0".."9","."}).
  5. 5Validate results by checking that VALUE() of extracted strings returns a number — if the result is text, wrap with VALUE().

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

How do I extract ALL numbers from a cell in Google Sheets (not just the first)?

Use =SPLIT(REGEXREPLACE(A2, "[^0-9.]+", " "), " ", TRUE, TRUE) to strip non-numeric characters and split on spaces — each number lands in its own cell.

Does the Excel formula handle decimal numbers?

The SUBSTITUTE/REPT approach works on space-separated tokens, so decimals like '3.14' are extracted whole if they are surrounded by spaces. Decimals embedded in words (e.g. '3.14kg') require Power Query or a LAMBDA-based character-by-character scan.

More on Text manipulation

See all →

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: