Function Problems

Extract the First Six Digits Only If Numeric in Excel

Steve KSteve K Dec 2, 2026 869 views

Question details

Extract the first six characters from a cell only when each character is a digit.

Extract the First Six Digits Only If Numeric in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A cell contains a six-digit identifier followed by descriptive text, such as 184412 MAIN FRAME UPDATE.
Observed behavior
The desired result is 184412 when the first six characters are digits, or a blank otherwise.
Before you start

Identify the cell containing the source text and choose an empty cell for the result. The formula below assumes the source is in A1 and checks for the digits 0 through 9.

Solution 1Recommended

Check and extract the first six digits with an Excel formula

Use this formula to require exactly six leading digit characters and preserve any leading zeros.

The formula checks the first six characters individually and returns them as text only when each is a digit.

1
Select an output cell

In Excel, click an empty cell such as B1 next to the source text in A1.

2
Enter the formula

Enter =IF(AND(LEN(A1)>=6,SUMPRODUCT(--ISNUMBER(FIND(MID(A1,{1,2,3,4,5,6},1),"0123456789")))=6),LEFT(A1,6),"") and press Enter.

3
Apply it to other rows

Drag the fill handle from the bottom-right corner of B1 down the column to check additional source cells.

Check and extract the first six digits with an Excel formula
Text result: The result preserves leading zeros. A shorter value or a non-digit among the first six characters returns a blank.
Work with spreadsheet formulas

Extract six leading digits in WPS Spreadsheet

Use the same digit-checking formula in WPS Spreadsheet to extract six leading digits while preserving leading zeros.

  1. 1. Open your spreadsheet: Open WPS Spreadsheet and use Open to select your Excel workbook.
  2. 2. Choose an output cell: Click an empty cell such as B1 next to the source text in A1.
  3. 3. Enter the formula: Enter =IF(AND(LEN(A1)>=6,SUMPRODUCT(--ISNUMBER(FIND(MID(A1,{1,2,3,4,5,6},1),"0123456789")))=6),LEFT(A1,6),"") and press Enter.
  4. 4. Fill down: Drag B1's fill handle down to apply the formula to the remaining rows.
Check all six leading characters before extracting themPreserve leading zeros in identifiersOpen and edit Microsoft Excel XLSX filesUse familiar spreadsheet formulas and fill handles
microsoft office alternative - wps office

Frequently Asked Questions

Will the formula keep leading zeros?

Yes. LEFT returns text, so a value beginning with 001234 produces 001234 rather than 1234.

What happens if a letter or space appears in the first six characters?

The formula returns a blank because each of the first six characters must be a digit from 0 through 9.

Can I return the extracted digits as a number?

If the text result is in B1, enter =IF(B1="","",VALUE(B1)) in another cell. Converting to a number removes leading zeros.

Why not just use IFERROR with LEFT and a double unary?

The formula =IFERROR(--LEFT(A1,6),"") converts numeric-looking text, but it does not strictly verify that there are six digit characters. It can also remove leading zeros.