Remove the First and Last Digits in Excel and WPS Spreadsheets
Question details
Extract the middle three digits from a five-digit value while preserving leading zeros.

- Product
- Microsoft Excel and WPS Spreadsheets
- Device & OS
- not provided
- Scenario
- A spreadsheet contains five-digit values, including values that begin with zeros, and the user needs the middle three digits.
- Observed behavior
- The desired result is a three-character value that retains any leading zeros in the extracted digits.
Identify the cell containing the value and confirm that each input is a nonnegative whole number with no more than five digits. The formulas below treat shorter numeric values as five-digit values padded with leading zeros.
Use MID and TEXT to preserve leading zeros
Use this formula when the extracted result must always contain three digits, including leading zeros.
Click an empty cell next to the source value, such as D2 when the value is in C2.
Type =MID(TEXT(C2,"00000"),2,3) and press Enter. Replace C2 with your source cell if needed.
Drag the output cell's fill handle down to copy the formula to the remaining rows.

Use QUOTIENT and MOD for a numeric result
Use this option when you need a number for calculations rather than a three-character text result.
Extract Middle Digits in WPS Spreadsheets
Use the MID and TEXT functions in WPS Spreadsheets to extract the middle three digits and retain leading zeros.
- 1. Open your spreadsheet: Open WPS Spreadsheets and select File > Open to choose your workbook.
- 2. Choose a result cell: Click an empty cell, such as D2, beside the source value in C2.
- 3. Enter the formula: Type =MID(TEXT(C2,"00000"),2,3) and press Enter.
- 4. Fill down and save: Drag the fill handle down for other rows, then select File > Save to save the workbook.

Frequently Asked Questions
How do I keep a leading zero in the extracted result?
Use =MID(TEXT(C2,"00000"),2,3). The formula returns text, so a result such as 020 retains its leading zero.
Can I use the extracted digits in calculations?
Yes. Enter =MOD(QUOTIENT(C2,10),1000) to return a numeric result. Leading zeros will not be stored as part of the number.
What happens if the source cell contains fewer than five digits?
The TEXT format 00000 pads the value with leading zeros before MID extracts the middle three characters. For example, 205 is treated as 00205 and returns 020.
Can I display a numeric result with three digits?
Yes. Select the result cell and apply the custom number format 000 through the cell formatting options. A value of 20 will display as 020, although it remains numeric 20.




