How to Use SUBSTITUTE and REPT in a Single Excel Formula
Question details
Create a single Excel formula to retain specific digits, remove unwanted periods, and replace remaining string lengths with zeros.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- A user needs to reformat a string of data by stripping out periods and applying zero-padding to reach a specific character count without using multiple helper cells.
- Observed behavior
- The user is seeking a more efficient, single-cell function approach to format their string data, rather than distributing the steps across multiple cells.
Verify the source cell reference and determine the exact fixed length you want the final padded text string to be before creating the formula.
Combine SUBSTITUTE, LEFT, and REPT Functions
Use a nested formula that combines string extraction, character substitution, and zero-padding to format the text within a single cell.
Instead of using multiple columns to clean and pad your data, you can nest several text functions together. The SUBSTITUTE function removes the periods, the LEFT function grabs the starting sequence, and the REPT function adds the exact number of zeros needed to reach your target length.
Use the SUBSTITUTE and LEFT functions to pull the first eight characters of the cell (e.g., A1) and remove any periods. The syntax is SUBSTITUTE(LEFT(A1,8),".","").
Subtract the length of the cleaned string from your target total length (e.g., 8). Use 8-LEN(SUBSTITUTE(LEFT(A1,8),".","")) to find out how many zeros are missing.
Use the REPT function to repeat the "0" character by the missing amount calculated in the previous step. The syntax is REPT("0", missing_amount).
Join the cleaned string and the padding zeros using an ampersand (&). The final formula is: =SUBSTITUTE(LEFT(A1,8),".","")&REPT("0",8-LEN(SUBSTITUTE(LEFT(A1,8),".","")))
Press Enter to apply the formula in the active cell, then click and drag the fill handle down to apply this formatting logic to the rest of the column.

Use Advanced Formulas Seamlessly in WPS Spreadsheet
WPS Office Spreadsheet provides full support for complex, nested text formulas including SUBSTITUTE, REPT, and LEN. You can effortlessly manage and clean your data with a familiar, highly compatible interface.
- 1. Open WPS Spreadsheet: Launch WPS Office and open the spreadsheet containing the data you wish to format.
- 2. Select the target cell: Click on the empty cell where you want the cleaned and padded string to appear.
- 3. Input the combined formula: Type the formula =SUBSTITUTE(LEFT(A1,8),".","")&REPT("0",8-LEN(SUBSTITUTE(LEFT(A1,8),".",""))) into the formula bar.
- 4. Apply the calculation: Press Enter to view the result, and use the fill handle to drag the formula down to apply it to other cells in the column.

Frequently Asked Questions
Can I use this formula to remove characters other than periods?
Yes, you can easily adapt the formula. Simply replace the "." in the SUBSTITUTE function with the specific character you wish to remove, such as a hyphen "-" or a comma ",".
How do I change the total fixed length of the final text string?
To change the desired output length, adjust the number in both the LEFT function and the subtraction operation inside the REPT function. For example, if you need a 10-character string, replace the instances of "8" with "10".
What happens if the initial string is already longer than the target length?
Because the formula utilizes the LEFT function (e.g., LEFT(A1,8)), it will automatically truncate the initial string at the specified character limit before applying the substitution and padding steps.
Can I pad the string with a character other than zero?
Absolutely. You can change the "0" in the REPT function to any other character or symbol you prefer, such as an asterisk "*" or a dash "-", and the formula will pad the empty space with that character.




