Excel can pull the numbers out of a mixed text-and-number string, but there is no single built-in "extract number" function. The shortest reliable route depends on your version: if you have Microsoft 365 or Excel 2021 or later, use TEXTJOIN with MID, ROW and IFERROR in one array-style formula; on older versions you can use the same approach with slight changes, or a small helper-column trick. Everything below uses only standard worksheet functions, so it works on Windows, Mac and Excel for the web. Function and ribbon labels can differ slightly by version and region, so if a menu name does not match exactly, look for the closest equivalent.
What You'll Need
- Excel 2016 or later (Microsoft 365, Excel 2019, 2021, or Excel for the web). The array formula below needs dynamic arrays, which arrived with Microsoft 365 and Excel 2021.
- Your text strings in a single column, one value per cell, with no merged cells in that column.
- A spare column to the right of your data for the extracted numbers.
- Basic comfort with typing a formula and pressing Enter.
Step-by-Step
- Lay out your data. Put the mixed strings in column A, starting at A1. For example:
Order AB-1024-X,SKU 55 blue,call 0800 123 456. Leave column B empty for the results. - Build the extraction formula for the first cell. In B1, type this and press Enter (do not type the outer braces; Excel adds them if your version needs them):
=TEXTJOIN("",TRUE,IFERROR(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)*1,"")) - Understand what it does, so you can adapt it.
MID(A1,ROW(...),1)walks through the string one character at a time. Multiplying each character by 1 turns digits into real numbers and forces text characters to an error.IFERRORswaps those errors for empty text, andTEXTJOINglues the surviving digits back together in their original order. That is whyAB-1024-Xbecomes1024. - Handle the decimal point if you need one. The formula above drops dots and commas because the decimal separator is not a digit. If your strings contain prices or measurements like
Size 12.5 cm, replace the trailing""with a rule that keeps the separator. The simplest safe change is to substitute a placeholder before extracting, then swap it back: wrap the whole formula inSUBSTITUTE(...,"PLACEHOLDER",".")after temporarily replacing the decimal character. Test on a copy first, because comma-versus-dot depends on your regional settings. - Fill the formula down. Click B1, grab the small square at the bottom-right corner, and drag down to the last row. If the selection is long, double-click that square and Excel fills to the end of the adjacent data automatically.
- Convert the results to real numbers. The output from
TEXTJOINis text that looks like a number, soSUMover column B may return 0. Fix it by prefixing the formula with a double negative or wrapping it inVALUE:=VALUE(TEXTJOIN(...)). Cells with no digits will show a#VALUE!error, so wrap the whole thing inIFERROR(...,"")to leave a blank instead. - Turn off macros-free legacy mode only if needed. In very old files saved as .xls, dynamic arrays are unavailable and the formula returns a single character. Save the workbook as .xlsx first, then re-enter the formula. This is a file-format problem, not a typo.
If your strings follow a fixed pattern, such as always starting with three letters, a plainer formula is easier to read: =MID(A1,4,4) slices out exactly four characters starting at position 4. Use the general formula only when the number's position and length vary.
Common Mistakes
- Typing the curly braces by hand. In versions without dynamic arrays you must enter the formula with Ctrl+Shift+Enter. Typing
{and}yourself creates a text string, not a formula. - Using the wrong row delimiter.
ROW(INDIRECT("1:"&LEN(A1)))assumes the string is shorter than the number of rows in the sheet. Very long strings can trigger an error; split them first. - Getting 0 when summing. The result is text. Wrap it in
VALUEas shown above before charting or totalling. - Losing leading zeros. Converting to a real number turns
007into7. If the zeros matter (part numbers, codes), leave the result as text and do not useVALUE. - Dragging the wrong reference. Relative references like A1 are correct when dragging down. Copy-pasting a formula sideways without adjusting will point at the wrong column.
- Assuming it handles negatives. A hyphen or minus sign is not a digit, so
-45comes out as45. You must detect and re-attach the sign yourself, for instance withIF(ISNUMBER(SEARCH("-",A1)),"-","").
Tips
- Keep a backup of the original column before you start. Paste values only into a new sheet if you plan to replace text permanently.
- Test the formula on five or six representative strings, including one with no digits and one with several numbers. Watch what happens to each before filling down thousands of rows.
- If you only need the first number in the string,
LOOKUPcombined withMIDcan be shorter, but the general formula above is easier to explain to a colleague later. - Freeze the header row so you can check columns while scrolling through long results.
- Use conditional formatting to highlight any blank results; blanks often reveal rows where the source text had no numbers at all.
Troubleshooting
The formula shows #NAME? Your version does not recognise TEXTJOIN. Update Excel, or use the helper-column method: put IFERROR(MID($A1,COLUMN(A1),1)*1,"") across several columns, then concatenate them.
You get #VALUE! on some rows Those strings contain no digits, so VALUE fails. Wrap the formula in IFERROR.
The formula is painfully slow INDIRECT is volatile and recalculates on every change. Convert finished results to values with Copy, then Paste Special > Values.
Results look right but totals are wrong Check for stray spaces; text that includes a space becomes blank rather than a number. Also confirm which rows are truly numeric by using ISNUMBER next to them.
Nothing changed after editing Calculation may be set to Manual. Open Formulas on the ribbon and set Calculation Options to Automatic.
If that did not work, simplify: put one example string in A1, build the formula there, and confirm the single result before filling down again.
Frequently Asked Questions
Is there a built-in Excel function that extracts numbers?
No. Excel has no dedicated extraction function. You combine MID, ROW, IFERROR and TEXTJOIN, or use the helper-column approach.
Does this work in Excel for the web and on Mac?
Yes, for Microsoft 365 versions, including the web app and Mac. Older perpetual versions may lack TEXTJOIN; check by typing it into an empty cell.
Can it pull out multiple separate numbers?
It joins all digits in the string into one number. For two distinct numbers you need a different approach, such as splitting the text at a fixed separator first.
Why does the result keep leading zeros?
Because it is still text. Wrapping in VALUE converts it to a number and removes the leading zeros. If you need them, leave it as text.
Can I extract only the last number in a string?
Not with this single formula. The most practical method is to reverse the string first (using a formula that flips the characters) and then take the first number, or use Power Query's split tools.
Is Power Query a better option?
Yes, for large or messy datasets. Split the column by non-digit characters and let Power Query load a clean result into a table. It handles thousands of rows faster than worksheet formulas.