How to Repeat Characters Using the REPT Function in Excel

When you are formatting a financial database in Microsoft Excel, you often need to pad raw data with filler characters to meet strict length requirements (e.g., forcing a 4-digit ID number to become a 10-digit ID number by injecting zeroes in front of it). Alternatively, you might want to create a highly visual, primitive bar chart directly inside a cell without using the complex graphing engine. To command Excel to mathematically duplicate a specific character or text string a precise number of times, you must use the REPT (Repeat) function.

How the REPT Function Works

The REPT function is incredibly straightforward. You feed it a piece of text, and you tell it exactly how many times to copy and paste that text in a continuous loop.

The syntax requires two arguments: =REPT(text, number_times)

If you want to spawn exactly ten zeroes in a row, click into an empty cell and type:

=REPT("0", 10)

Excel will instantly output: 0000000000.

Padding Text with the REPT Function

The true power of REPT is unleashed when you combine it with other cells to dynamically pad data. Imagine cell A2 contains the ID number 4592 (which is 4 characters long). Your database requires every ID to be exactly 10 characters long, padded with leading zeroes.

Instead of manually typing zeroes, you can calculate the exact number of zeroes required by subtracting the length of the ID from 10, and then using REPT to generate them.

=REPT("0", 10-LEN(A2)) & A2

Excel calculates that 4592 is 4 characters long. It subtracts 4 from 10, leaving 6. The REPT function instantly generates exactly six zeroes (000000), and the & symbol seamlessly glues the original ID number onto the end, outputting the perfectly formatted string: 0000004592.

Creating In-Cell Bar Charts

You can also use the REPT function to build highly aesthetic, lightweight visual data dashboards without touching the heavy “Insert Chart” menus.

Imagine cell B2 contains a customer satisfaction score of 5. You want to visually represent this as a 5-star rating.

=REPT("★", B2)

Excel looks at the number 5, grabs the solid star character, and repeats it exactly 5 times (★★★★★). If the score in B2 drops to a 2, the cell instantly and automatically shrinks to two stars (★★). This technique is highly effective for building minimalist progress bars using the standard pipe character (|).

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.