Leading zeros

%3CLINGO-SUB%20id%3D%22lingo-sub-2435908%22%20slang%3D%22en-US%22%3ELeading%20zeros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2435908%22%20slang%3D%22en-US%22%3E%3CP%3EGood%20Morning%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20lost%20my%20leading%200's%20on%20all%20of%20my%205%20digit%20product%20numbers.%20Is%20there%20an%20If%20statement%20that%20can%20find%20anything%20with%20a%204%20digit%20number%20to%20add%20a%20leading%200%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2435908%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2436064%22%20slang%3D%22en-US%22%3ERe%3A%20Leading%20zeros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2436064%22%20slang%3D%22en-US%22%3EHi!%20Assuming%20your%20prduct%20numbers%20are%20in%20A%3AA%2C%20this%20will%20work.%3CBR%20%2F%3E%3CBR%20%2F%3E%3DREPT(0%2C5-LEN(A9))%26amp%3BA9%3CBR%20%2F%3E%3CBR%20%2F%3EIt%20adds%20repeating%20zeroes%20for%20any%20missing%20characters%20up%20to%205%20characters%2C%20then%20adds%20that%20to%20the%20front%20of%20the%20same%20cell.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2436190%22%20slang%3D%22en-US%22%3ERe%3A%20Leading%20zeros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2436190%22%20slang%3D%22en-US%22%3EThanks!%20I%20am%20still%20doing%20something%20wrong%2C%20as%20this%20is%20changing%20the%20value%20of%20the%20cell%20-%20its%20calculating%20a%20value.%20I%20just%20want%20to%20put%20a%200%20in%20front%20of%20the%20current%20number.%20Should%20I%20have%20made%20them%20text%20fields%20first%3F%3CBR%20%2F%3Ethanks%20for%20your%20help!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2436266%22%20slang%3D%22en-US%22%3ERe%3A%20Leading%20zeros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2436266%22%20slang%3D%22en-US%22%3ENot%20sure%20exactly%20what%20you%20want%20your%20end%20product%20to%20look%20like%2C%20do%20you%20want%20it%20to%20be%20all%20text%3F%20Would%20something%20like%20this%20work%3F%20This%20is%20unaffected%20if%20you%20convert%20cell%20format%20to%20text.%20%3DIF(LEN(A2)%3D4%2C0%26amp%3BA2%2CA2)%3CBR%20%2F%3E%3CBR%20%2F%3EWhen%20I%20try%20the%20REPT%20formula%20on%20my%20end%20it%20doesn't%20change%20any%20of%20the%20calculations%20ran%20off%20of%20it.%3C%2FLINGO-BODY%3E
New Contributor

Good Morning, 

 

I lost my leading 0's on all of my 5 digit product numbers. Is there an If statement that can find anything with a 4 digit number to add a leading 0? 

 

Thanks! 

7 Replies
Hi! Assuming your prduct numbers are in A:A, this will work.

=REPT(0,5-LEN(A9))&A9

It adds repeating zeroes for any missing characters up to 5 characters, then adds that to the front of the same cell.
Thanks! I am still doing something wrong, as this is changing the value of the cell - its calculating a value. I just want to put a 0 in front of the current number. Should I have made them text fields first?
thanks for your help!
Not sure exactly what you want your end product to look like, do you want it to be all text? Would something like this work? This is unaffected if you convert cell format to text. =IF(LEN(A2)=4,0&A2,A2)

When I try the REPT formula on my end it doesn't change any of the calculations ran off of it.
Hello,
If your data is formatted as text, then DKoontz formula should work.
However, if your data is formatted as a number, then try using a custom number format like "00000" for a 5 digit number with leading zeros.
I'd like to offer one other alternative to DKoontz formula.
I've always been one for simplicity, so I sometime use something like this:
=RIGHT("00000" & A2,5)
This will work for any length number up to 5 digits long. And has the added benefit of formatting the result as text so the leading zeros don't disappear again.
I like this solution

@DKoontz 

 

Thanks! BOTH options worked great!!