Extract the First Six Digits Only If Numeric in Excel
Question details
Extract the first six characters from a cell only when each character is a digit.

- 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.
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.
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.
In Excel, click an empty cell such as B1 next to the source text in A1.
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.
Drag the fill handle from the bottom-right corner of B1 down the column to check additional source cells.

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. Open your spreadsheet: Open WPS Spreadsheet and use Open to select your Excel workbook.
- 2. Choose an output cell: Click an empty cell such as B1 next to the source text in A1.
- 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. Fill down: Drag B1's fill handle down to apply the formula to the remaining rows.

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.




