Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Formula to Return Just Numbers: A How-To

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To return just the numbers from a cell that mixes text and digits, use a formula that extracts numeric characters. In Excel 365 or Excel 2021, the simplest approach is =TEXTJOIN("",TRUE,IFERROR(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)*1,"")) entered as a normal formula (it spills automatically). For older Excel versions without TEXTJOIN, you need a helper column or a VBA user-defined function. The formula works by checking each character: if multiplying it by 1 does not produce an error, it is a number and gets kept; otherwise it is dropped.

What You'll Need

  • Excel 365, Excel 2021, or Excel 2019 with dynamic arrays (for the TEXTJOIN method). Older versions can use the helper-column method described below.
  • A cell containing mixed text and numbers, for example Order 12345A or SKU-9876-X.
  • Basic familiarity with entering formulas and copying them down a column.

Step-by-Step

  1. Identify your source cell. Suppose the mixed value is in cell A2. You want the extracted number to appear in B2.
  2. Enter the extraction formula in B2. In Excel 365 or 2021, type:
    =TEXTJOIN("",TRUE,IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)*1,""))
    Press Enter. The formula returns only the digits from A2 as a text string.
  3. Convert the result to a real number. The TEXTJOIN result is text. To use it in calculations, wrap it with VALUE or double unary minus: =VALUE(TEXTJOIN("",TRUE,IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)*1,""))). If the cell contains no digits, this returns an error; wrap with IFERROR to show blank: =IFERROR(VALUE(TEXTJOIN("",TRUE,IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)*1,""))),"").
  4. Copy the formula down. Drag the fill handle from B2 down to cover all rows with data. Each row extracts its own number.
  5. For older Excel versions (2016 and earlier) without TEXTJOIN: use a helper column approach. In B2 enter =IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)*1,"") and press Ctrl+Shift+Enter (array formula). This returns an array; then in C2 use =TEXTJOIN("",TRUE,B2) if TEXTJOIN exists, or concatenate manually with a series of IF statements across columns. Alternatively, use a simple VBA user-defined function (see Tips).
  6. Verify the output. Check that the extracted number matches the digits in the original cell. For example, Order 12345A should yield 12345. If the original has multiple number groups like AB12CD34, the formula concatenates all digits into 1234; if you need only the first group, a different approach is required (see Common Mistakes).
  7. Optional: remove leading zeros. The VALUE conversion drops leading zeros automatically. If you need to keep them as text, skip the VALUE step.

Common Mistakes

  • Expecting the formula to separate multiple number groups. The formula above joins all digits into one string. For AB12CD34 it returns 1234, not 12 and 34. To extract only the first number group, use a more complex formula or Power Query.
  • Forgetting to convert text to number. TEXTJOIN returns text, so SUM or arithmetic may ignore it. Always wrap with VALUE or multiply by 1.
  • Using INDIRECT with large ranges. The ROW(INDIRECT("1:"&LEN(A2))) construction works per cell but can be slow on thousands of rows. For large datasets, consider Power Query or a VBA function.
  • Not handling empty cells. If A2 is blank, LEN(A2) is 0, and the formula may error. Wrap the whole formula in IF(A2="","",...) to avoid errors.
  • Assuming the formula works in Excel 2016. TEXTJOIN is not available in Excel 2016 or earlier without a Microsoft 365 subscription. Use the helper-column method or VBA instead.

Tips

  • For a reusable solution, create a VBA user-defined function. Press Alt+F11, insert a module, and paste a function that loops through characters and keeps digits. Save as .xlsm. This works in all Excel versions.
  • If you need to extract numbers from text in many columns, Power Query (Data > Get & Transform Data) offers a more robust way: split by non-digit characters.
  • Use =IFERROR(VALUE(...),"") to avoid #VALUE! errors when no digits are present.
  • Test on a copy of your data first, especially if you plan to replace the original column.

Troubleshooting

  • Formula returns #VALUE!: Check that the cell reference is correct and that the cell contains at least one digit. If the cell is empty, wrap with IF(A2="","",...).
  • Formula returns #NAME?: TEXTJOIN is not recognized. You are likely on Excel 2016 or earlier. Use the helper-column method or VBA.
  • Result is text, not a number: Wrap with VALUE or multiply by 1. If you see a green triangle in the cell, click it and choose Convert to Number.
  • Formula is slow: For large ranges, avoid INDIRECT. Use Power Query or a VBA function that processes the range in memory.
  • Extracted number is wrong: Check for hidden characters or spaces. Use TRIM and CLEAN on the source cell first: =TRIM(CLEAN(A2)).

Frequently Asked Questions

Can I extract numbers from a cell without a formula?

Yes, use Flash Fill: type the expected number in the adjacent cell, then press Ctrl+E. Excel will attempt to fill the rest. It works well for consistent patterns but is not dynamic.

Does this formula work in Excel for Mac?

Yes, TEXTJOIN and dynamic arrays are supported in Excel for Mac (Office 365 and 2021). The keyboard shortcuts differ, but the formula syntax is the same.

How do I extract only the first number group from a string?

Use a formula with MIN and FIND to locate the first digit, then extract until the first non-digit. This is more complex; Power Query or VBA is often easier.

Will this formula work on numbers with decimals?

No, it only keeps digits 0-9. Decimal points are treated as non-numeric and removed. To keep decimals, you need a custom function that recognizes the decimal separator.

Can I use this formula to extract numbers from a range of cells at once?

Yes, in Excel 365 you can enter the formula in one cell and it will spill down if you reference a range, but you may need to use BYROW or MAP for complex cases. For most users, copying down is simpler.

What if my data contains negative numbers?

The formula strips the minus sign because it only keeps digits. To preserve negatives, you need a more advanced formula that checks for a leading minus.