As the formula is copied down, the numbers in column B are padded with a progressively larger number of zeros based on the number in column C. Note that the result is a text value.

Fixed number

The TEXT function returns a number formatted as text, using the number format provided. The TEXT function can apply number formats of any kind to numbers. It is most often used when you want to maintain number formatting for a number when concatenating that number with other text. For example to use the TEXT function to pad a number 3, 4, and 5 zeros: Notice the number format works by adding adding zeros to the left as needed to reach the total number of zeros supplied.

Variable number

To allow a variable number of zeros based on a number in another cell, we can add the REPT function into the mix. The REPT function simply repeats a text string a given number of times: So to pad a number with 5 zeros, we can use REPT to assemble the five zeros into  the text"00000": The formula used in the example shown is simply a variation on the above formula. The formula in E9 evaluates like this:

Other characters

You can adapt this formula to use any character you like:

Pad for display only

Padding a number with zeros with the TEXT function changes the number into text, which may not suit your needs. To simply display a number with padding, you can use a regular number format. For example, to pad a number with 5 zeros for display only, select the cells and use the shortcut Control + 1 to open the Format Cells window.  Then: With this approach, the number is not converted to text, but remains a true number. More details here.

Dave Bruns

Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.