Question

I made the mistake a while back of stripping the leading zeros off of some data that I know has a length of n digits. I have filtered for only those with less than n digits, and there are variable lengths. Is there a way to use the REPLACE function or something else to account for the fact that I want to keep adding zeros to these filtered cells until the length becomes n?

EDIT: My current function is simply

=IF(LEN(K2)=n-1,CONCATENATE(0,K2),IF(LEN(K2)=n-2,CONCATENATE(0,0,K2),IF(LEN(K2)=n-3,CONCATENATE(0,0,0,K2),....,""))) 

but I imagine there must be a more efficient formula.

Was it helpful?

Solution

Eg:

=RIGHT("00000" & A1, 5)

Or:

=RIGHT(REPT("0",5) & A1, 5)

Adjust the 5 to the total padded length you want.

OTHER TIPS

If all the number in the column are the same length you could do custom formatting = 0000000 with the number of 0's you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top