Excel Snippets: Formula to Zero Pad to 6 Digits

A colleague posted an Excel formula which could be used to zero pad a column in Excel, which was to be used as the ID column for data being integrated to Microsoft Dynamics 365 Business Central. The formula they had used was longer and more convoluted than was needed.
In fact you only need to use one function to zero pad. That function is TEXT
which you provide with two parameters; the cell you want to zero pad and a string of zeros, the length of the output required.
So, to zero pad cell A2 with 6 zeros we would use the following:
=TEXT($A2, "000000")
You can also use the REPT
function to provide the required zero [adding length, which if you’re dealing with a long string can ease readability).
The REPT
function takes two parameters; the first is the character to repeat and the second is the number of times to repeat:
=TEXT($A2 ,REPT("0", 6))
Click to show/hide the Excel Snippets Series Index
Read original post Excel Snippets: Formula to Zero Pad to 6 Digits at azurecurve|Ramblings of an IT Professional
This was originally posted here.
*This post is locked for comments