REPT()

SyntaxREPT(text,number_times)

Definition. This function repeats text a given number of times.

Arguments

Background. Use the REPT() function to fill a cell with a specified number of instances of a text string. You can also use this function for chart-like illustrations in worksheets.

Also note the following when working with this function:

Example. Assume that the cell range F6:F16 contains names, and the cell range G6:G16 contains scores. You want to show both the names and the scores in H6:H16, with the names on the left and the scores on the right. The cell width should be adjusted as necessary.

Create an auxiliary column (I) to calculate the maximum total length for the names and scores. Select the range I6:I16, and enter the following formula:

=MAX(LEN(F6:F16)+LEN(G6:G16))+1

Press Ctrl+Shift+Enter. The array formula enclosed in braces calculates the maximal necessary length for the names and scores in each line. Enter the formula

=F6&REPT("  ",I6-LEN(F6)-LEN(G6))&G6

in cell H6 (see Figure 8-9) and copy it into the cells below H6. Based on the maximal total length and the actual total length in the row, you can calculate the necessary space.

Caution

This example makes sense only when using nonproportional fonts (such as Courier), in which all characters are the same width.

Using REPT() to fill in spaces.

Figure 8-9. Using REPT() to fill in spaces.

See Also

CONCATENATE(), REPLACE(), SUBSTITUTE()