Excel Remove Text and Keep Numbers in a Cell

How-to basics · Updated November 19, 2026

To remove letters and symbols while keeping every digit in an Excel cell, enter =IF(A2="","",TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,""))) in B2, assuming the mixed text is in A2, then fill the formula down. In Excel for Microsoft 365, it returns the digits as text, so a value such as “Order 58-A9” becomes “589.”

What “remove text and leave numbers” means

The right solution depends on what counts as a number in your data. The formula above keeps the characters 0 through 9 and removes everything else. That is useful for extracting an account code from “AC-1047-X,” a phone number from “(415) 555-0198,” or a quantity from “12 boxes.” It does not interpret the result as a mathematical value; it assembles a text string of digits.

That distinction matters. “0074” may be an ID whose leading zeros must remain, while “74” may be a quantity you want to add. A decimal such as “3.75” contains a period, which the digit-only formula removes, producing “375.” A minus sign is also removed, so “-24” becomes “24.” Decide whether punctuation is merely unwanted decoration or part of the number before choosing a method.

Also distinguish actual cell contents from their appearance. If a cell contains the numeric value 123 but a custom format displays it as “ID-00123,” the letters and padded zeros may exist only in the number format. A text-extraction formula reads the stored value, not necessarily the formatted display. Imported data containing literal characters behaves differently.

How the Microsoft 365 formula works

With the source value in A2, this formula examines one character at a time and joins the characters that can be converted to digits:

=IF(A2="","",TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,"")))

LEN(A2) counts the characters. SEQUENCE creates positions from 1 through that count, and MID returns the character at each position. Multiplying each character by 1 tests whether it can be read as a number: a digit succeeds, while a letter, space, hyphen, or other non-digit produces an error. IFERROR replaces those errors with empty text, and TEXTJOIN combines the remaining characters without a separator. The outer IF keeps an empty source cell empty.

For example, if A2 contains “Ref: 08A-31,” the formula returns “0831.” It keeps digits in their original order, even when they are separated by words or punctuation. It does not sort digits, select only one numeric group, or retain a decimal point. The formula uses SEQUENCE, available in Microsoft 365 and Excel 2021 or later; it is intended for current Excel on Windows.

Apply the formula to a column

  1. Put the mixed text in column A, with the first record in A2. Add a heading such as “Digits only” to B1.
  2. Enter the formula in B2. Confirm that the result contains the digits you expect.
  3. Copy the formula down by dragging the fill handle at the lower-right corner of B2, or double-click that handle to fill alongside a neighboring column of data.
  4. Check representative rows, especially values with leading zeros, punctuation, or more than one group of digits.
  5. If you need a fixed result rather than formulas, copy the output cells and use Home > Paste > Paste Values. Keep the original column until you have verified the results.

The formula refers to A2 with a relative reference, so Excel changes it to A3, A4, and so on as it fills down. On Excel for the web, the formula approach also works in supported Microsoft 365 workbooks, although ribbon labels and some data-import options can differ from the Windows desktop application.

Keep the result as text or convert it to a number

Keeping the extracted digits as text is usually best for phone numbers, postal codes, product identifiers, and account references. Those values identify something rather than measure it, and leading zeros can be significant. A text result also avoids Excel changing a long identifier into scientific notation or dropping precision.

If the digits represent a quantity for arithmetic, convert the result in a separate column. With the formula output in B2, use this in C2:

=IF(B2="","",VALUE(B2))

For example, if B2 contains the text “589,” the formula returns the number 589, which can be summed or used in calculations. A numeric conversion removes leading zeros: “0074” becomes 74. Excel also supports only 15 significant digits of numeric precision, so do not convert long IDs or account numbers if every digit must be preserved. Formatting a numeric result to show leading zeros changes how it displays, but it does not turn the value back into an identifier stored as text.

What if the number includes a decimal point or minus sign?

The digit-only formula deliberately discards all punctuation. If your source strings contain decimals or negative numbers, that can change their meaning. For example, “Balance: -18.50” becomes “1850,” not -18.50. Do not use the digit-only result for calculations in that situation.

When the format is consistent, a targeted cleanup can be safer: remove known labels or units while leaving the numeric punctuation in place. For example, with text in A2 that always ends in “ kg,” the formula =SUBSTITUTE(A2," kg","") removes that exact suffix. It will not remove arbitrary letters elsewhere, and inconsistent spaces or units may need separate handling. Check whether the decimal separator is a period or comma in the source and whether that matches the workbook’s regional settings before converting the cleaned text to a number.

If entries contain varying labels and punctuation but you still need a correctly interpreted signed decimal, define the permitted number format first. A general “keep digits” operation cannot reliably guess whether a comma means a decimal mark or a thousands separator, or whether a hyphen is a minus sign or part of an ID.

Other ways to remove text

  • Find and Replace: Use this when the unwanted text is known and repeats consistently, such as one fixed prefix. In Excel for Windows, press Ctrl+H to open Find and Replace, enter the exact text in Find what, leave Replace with empty, and choose Replace All. This removes only the specified characters; it is not a general method for stripping every letter.
  • Power Query: Use this to clean a larger imported table or repeat the same cleanup during data refresh. In Excel for Microsoft 365 on Windows, select a cell in the table and choose Data > From Table/Range. In Power Query Editor, choose Add Column > Custom Column and enter Text.Select([Column1], {"0".."9"}), replacing Column1 with the actual column name. This keeps the ASCII digits 0 through 9. Choose Home > Close & Load to return the transformed data to Excel. Power Query is useful when the cleanup must be repeatable, but it creates a query result rather than directly editing the original cells.
  • Manual editing or Flash Fill: For a few rows, typing the desired result may be quickest. Flash Fill can recognize a pattern from examples: enter the first cleaned value next to the source, then use Data > Flash Fill or Ctrl+E on Windows. Review the generated results carefully; pattern-based filling may not handle every variation and does not update like a formula when source data changes.

On Mac, Excel has Find and Replace and formulas, but Power Query availability and capabilities depend on the Excel release. If a listed Power Query command is absent, use the formula method or check the current features available in that Mac version.

Common problems and checks

  • It removes a decimal or a minus sign: That is expected for a digits-only extraction. Use a format-specific cleanup if those marks carry numeric meaning.
  • Leading zeros seem missing: The formula returns text, which can preserve them. Check that the output cell has not been converted to a number or replaced with a numeric conversion formula.
  • The formula returns an error: Check that the source reference is correct and that the formula is entered in a version with SEQUENCE. An empty input is handled by the outer IF; errors already present in the source should still be investigated.
  • Some digits are not retained: This method targets ordinary characters 0–9. Numerals from other writing systems, superscript digits, or special number symbols may not convert using the same test. Inspect those characters and decide whether they should be normalized or preserved separately.
  • A displayed code is not extracted as shown: The source may be a number with a custom format rather than text containing those visible characters. Check the formula bar and cell format, or convert the displayed representation to text as a separate, deliberate step.
  • Results do not change after editing the source: Confirm that calculation is set to Automatic under Formulas > Calculation Options, and that the result cells still contain formulas rather than pasted values.

Before replacing a source column, compare several outputs with their original entries and retain a backup if the data is important. Removing non-digits is a transformation: once letters or separators are discarded, the resulting digits may no longer identify the original value unambiguously.

Frequently Asked Questions

Can Excel remove letters but keep numbers automatically?
Yes. In Microsoft 365, use the formula above and fill it down. For recurring imports, Power Query can apply a digit-selection step during refresh. A formula recalculates when its source changes; pasted values and manual replacement do not.

How do I remove numbers and leave text instead?
That is the reverse operation and needs a different character test. The formula in this article treats digits as the characters to keep, so it cannot simply be used unchanged to retain letters. For predictable data, remove known digits or use a suitable text-cleaning process and check punctuation and spaces in the result.

Can I remove text without a formula?
Yes, if the unwanted part is predictable. Find and Replace can delete a known repeated prefix or suffix, while Flash Fill can infer a pattern from examples. Neither is as dependable as a formula or query when every row has different text mixed between its digits.

Will the formula keep phone number formatting?
It keeps digits only, so it removes parentheses, spaces, plus signs, and hyphens. A phone number such as “+1 (415) 555-0198” becomes “14155550198.” That output is best treated as text; the formula does not decide how to format or validate a telephone number.

Can I use this on a whole column without changing the original?
Yes. Put the formula in a neighboring column and fill it down. That leaves the source intact and makes it easy to compare values. If you later want to replace the source, copy the reviewed results and paste values, but retain a backup first.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.