Why Excel drops UPC leading zeros and how to get them back
A UPC is a code, not a number, but Excel does not know that. When it opens a CSV file or gets a pasted column of digits, it stores them as numbers, and a number has no zeros at the start. The UPC 012345678905 becomes 12345678905, and the listing that uses it fails.
What Excel does to a UPC column
- Leading zeros disappear. Many UPCs start with 0, so an 11-digit or 10-digit value in a UPC column almost always means lost zeros.
- Long codes turn into scientific notation. In the General format Excel shows a 12-digit code as 1.23457E+11. If the file is saved as CSV in this state, only the digits shown are saved and the rest are gone.
- Codes become decimals. Some exports write a UPC as 12345678905.0, which is not a valid code.
How to restore the codes safely
Adding zeros in front until the code has 12 digits is only half the job. The last digit of a UPC is a check digit calculated from the others, so after adding the zeros, check it. If it is right, the code is restored. If it is wrong, the code had another error besides the lost zeros, and guessing the missing digits would give you a code that belongs to someone else's product. Take those codes from the supplier again.
Codes shown as 1.23457E+11 cannot be restored at all: the digits are not in the file. They have to come from the original source.
The UPC leading zeros fixer does this for a pasted column: it restores the codes whose check digit is right and lists the rest with the reason. To check a single code, use the UPC check digit calculator.
Fixing the codes in Google Sheets
Google Sheets also treats digits as a number: type 036000291452 and the cell shows 36000291452. A 12-digit code is shown in full, so the scientific notation problem is mostly an Excel one.
To add the zeros back, put this in a new column, then fill it down:
=TEXT(A2,"000000000000")
Then check each 12-digit UPC. This formula returns TRUE when the check digit is right and FALSE when it is not:
=MOD(10-MOD(SUMPRODUCT(MID(B2,{1,3,5,7,9,11},1)*3)+SUMPRODUCT(MID(B2,{2,4,6,8,10},1)*1),10),10)=VALUE(RIGHT(B2,1))Here B2 is the cell with the restored code. For 036000291452 it returns TRUE, for 036000291453 FALSE. Codes with FALSE had another error besides the lost zeros, so take them from the supplier again.
A template with both formulas filled down to row 1001 and a short how-to sheet: download the UPC template (XLSX).
To keep a single code as text, start it with an apostrophe: '036000291452. For a whole column, select it and choose Format, Number, Plain text before typing or pasting.
How to keep it from happening again
- Do not open a CSV file by double-clicking it. In Excel use Data, From Text/CSV, and set the UPC column type to Text before loading.
- Before pasting codes into a sheet, format the column as Text.
- In Google Sheets, select the column and choose Format, Number, Plain text before pasting.
- After saving, open the CSV in a text editor once and check that the codes have all their digits.