# Pad a number with zeros

To pad a number with a variable number of zeros, you can use a formula based on the TEXT function and the REPT function. In the example show, the formula in D5 is:

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.

In this example, the goal is to pad a number with zeros. To illustrate how Excel functions can be combined, the number of zeros to use is variable, and comes from column C. The formula used to solve this problem combines the TEXT function and the REPT function.

### 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:

Format cells > Number > Custom > "00000"

With this approach, the number is not converted to text, but remains a true number. More details here.

## Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.

## Download 100+ Important Excel Functions

Get over 100 Excel Functions you should know in one handy PDF.