Function Problems

Remove the First and Last Digits in Excel and WPS Spreadsheets

Huda QurayshiHuda Qurayshi Dec 2, 2026 869 views

Question details

Extract the middle three digits from a five-digit value while preserving leading zeros.

Remove the First and Last Digits from a Five-Digit Number
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.
Before you start

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.

Solution 1Recommended

Use MID and TEXT to preserve leading zeros

Use this formula when the extracted result must always contain three digits, including leading zeros.

1
Select an output cell

Click an empty cell next to the source value, such as D2 when the value is in C2.

2
Enter the formula

Type =MID(TEXT(C2,"00000"),2,3) and press Enter. Replace C2 with your source cell if needed.

3
Apply it to other rows

Drag the output cell's fill handle down to copy the formula to the remaining rows.

Use MID and TEXT to preserve leading zeros
The result is text: For example, a source value represented as 00205 returns 020. TEXT supplies the five-digit representation, and MID extracts characters two through four.
WPS Spreadsheets

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. 1. Open your spreadsheet: Open WPS Spreadsheets and select File > Open to choose your workbook.
  2. 2. Choose a result cell: Click an empty cell, such as D2, beside the source value in C2.
  3. 3. Enter the formula: Type =MID(TEXT(C2,"00000"),2,3) and press Enter.
  4. 4. Fill down and save: Drag the fill handle down for other rows, then select File > Save to save the workbook.
Preserves leading zeros in the extracted three-character resultSupports Microsoft Excel XLS and XLSX filesLets you copy the formula across multiple rowsProvides a familiar spreadsheet interface
microsoft office alternative - wps office

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.