Remove Spaces from UPC Codes in Excel Without Losing Leading Zeros
Question details
Remove spaces from UPC codes while preserving or restoring leading zeros and keeping formulas available after saving.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user is cleaning UPC codes such as 0000 007 1600 and wants an 11-digit result.
- Observed behavior
- Leading zeros may be lost when a code is converted to a number, and formulas may not remain usable after the data is saved as plain text.
Check whether the UPC cells are stored as text or numbers, and confirm the required code length. If importing a text or CSV file, set the UPC column to Text during import so Excel does not remove its leading zeros.
Remove spaces from UPC codes stored as text
Use SUBSTITUTE when the original codes still contain their leading zeros.
In an empty cell such as B2, enter =SUBSTITUTE(A2," ","") and press Enter. Replace A2 with the cell containing your UPC code.
Select B2 and drag its fill handle down to apply the formula to the remaining codes. For example, 0000 007 1600 becomes 00000071600.
Select File > Save As and choose Excel Workbook (*.xlsx) to keep the formulas in the workbook.

Restore leading zeros to numeric UPC codes
Use TEXT when Excel has converted a code to a number and you know the required digit length.
Clean UPC Codes with WPS Spreadsheets
Use formulas in WPS Spreadsheets to remove spaces from text codes or pad numeric codes to a known length, then save the workbook with its formulas.
- 1. Open the spreadsheet: Open WPS Spreadsheets and select Open to load the workbook containing your UPC codes.
- 2. Remove spaces: In an empty cell, enter =SUBSTITUTE(A2," ","") for a code stored as text, then press Enter.
- 3. Pad numeric codes if needed: For a code already stored as a number, enter =TEXT(A2,REPT("0",11)) instead, changing 11 to the required digit count.
- 4. Fill and save: Drag the formula cell's fill handle down, then select File > Save As and choose an XLSX workbook.

Frequently Asked Questions
How do I keep leading zeros when importing UPC codes into Excel?
Select Data > From Text/CSV, choose the file, and set the UPC column's data type to Text during import. This prevents Excel from treating the codes as numbers.
Why did my formulas disappear after saving?
A plain-text file such as CSV does not reliably preserve spreadsheet formulas and workbook features. Use File > Save As and select Excel Workbook (*.xlsx) to retain them.
Can I replace the original UPC column with the cleaned codes?
Yes. Copy the formula results, select the destination cells, and use Home > Paste > Paste Special > Values. The pasted results will no longer depend on the formulas.
Can Excel recover the original leading zeros from a number?
Excel cannot infer how many zeros were originally present. If you know the required length, use =TEXT(A2,REPT("0",11)), replacing 11 with that length.




