Add leading zeroes/0's to existing Excel values to certain length
=TEXT(A1,"0000")
However the TEXT function is able to do other fancy stuff like date formating, aswell.
The more efficient (less obtrusive) way of doing this is through custom formatting.
- Highlight the column/array you want to style.
- Click ctrl + 1 or Format -> Format Cells.
- In the Number tab, choose Custom.
- Set the Custom formatting to 000#. (zero zero zero #)
Note that this does not actually change the value of the cell. It only displays the leading zeroes in the worksheet.
I hit this page trying to pad hexadecimal values when I realized that DEC2HEX()
provides that very feature for free.
You just need to add a second parameter. For example, tying to turn 12
into 0C
DEC2HEX(12,2)
=> 0C
DEC2HEX(12,4)
=> 000C
... and so on