FormulaCraft

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

Topic:Text manipulation

Heads up: Excel and Google Sheets do this differently.

Excel
=SUMPRODUCT(MID(0&A2,LARGE(INDEX(ISNUMBER(VALUE(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)))*ROW(INDIRECT("1:"&LEN(A2))),0),ROW(INDIRECT("1:"&LEN(A2))))+1,1)*10^(ROW(INDIRECT("1:"&LEN(A2)))-1))
Google Sheets
=IFERROR(VALUE(REGEXEXTRACT(A2,"[0-9]+")),0)

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, use =IFERROR(VALUE(REGEXEXTRACT(A2,"[0-9]+")),0) — REGEXEXTRACT pulls the first sequence of digits and VALUE converts it to a number.
  2. 2In Excel 365, use =TEXTJOIN("",TRUE,IF(ISNUMBER(VALUE(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1))),MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1),"")) entered as an array formula (Ctrl+Shift+Enter in older Excel).
  3. 3To extract all digit groups (not just the first), use REGEXEXTRACT with a global match in Sheets: =ARRAYFORMULA(REGEXEXTRACT(A2,"[0-9]+")).
  4. 4Wrap any result in VALUE() to convert the returned text digits into a true number for arithmetic.

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

Will this extract multiple separate numbers from one cell?

REGEXEXTRACT returns the first match only. Use REGEXEXTRACT with an array or a helper column to get subsequent numbers.

What if there are no numbers in the string?

Wrap in IFERROR to return 0 or blank: =IFERROR(VALUE(REGEXEXTRACT(A2,"[0-9]+")),"").

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: