Example 1
A divider line
C2 =REPT("-",20)
Result: --------------------
Twenty dashes. Change the second argument to change the length.
C2 =REPT("-",20) returns --------------------
Repeats text a given number of times. Use it for in-cell bars, dividers and padding.
Syntax
=REPT(, )
All versions of Excel.
Try it
Edit the formula in C2 or change the inputs. The sheet recalculates as you type.
C2 =REPT("-",20) returns --------------------
REPT repeats text a number of times. It looks like a trick function, but it covers three practical jobs: drawing small bar charts inside cells, building dividers and templates, and padding text to a fixed width.
=REPT("-",20) returns twenty dashes. =REPT("ab",3) returns ababab.
If number_times has a fraction, REPT drops it, so =REPT("x",2.9) returns xx. A zero returns an empty string, and a negative number returns #VALUE!. The result can't be longer than 32,767 characters, or the formula returns #VALUE! too.
Make the repeat count depend on a value and you have a bar. =REPT("|",B2/10) draws one bar character for every 10 units, so 40 units gives ||||. Fill it down a column and you get a quick visual comparison with no chart. Use a character that looks solid in your font, such as |, █ or ■. Scale the value so the longest bar fits the column. Because REPT drops fractions, round first if you want normal rounding: =REPT("|",ROUND(B2/10,0)).
To make IDs a fixed length, repeat zeros for however many are missing and join the ID: =REPT("0",8-LEN(A2))&A2 turns 412 into 00000412. This works on IDs stored as text, and it stays correct whatever the ID's length, as long as the ID is not longer than 8 characters. If it is, 8 minus its length goes negative and REPT returns #VALUE!. For numbers, TEXT with a format such as "00000000" is the shorter option.
REPT creates the mask in a replacement: =REPLACE(A2,1,LEN(A2)-4,REPT("*",LEN(A2)-4)) hides all but the last four characters of an account number, however long it is. See REPLACE.
Join a repeated character with a label for headings in a text report: =REPT("=",30). In a cell with Wrap Text on, a repeated CHAR(10) adds blank lines between items.
REPT repeats the whole text. =REPT("-+",5) gives -+-+-+-+-+. REPT has no separator option, so a repeat with commas between the copies means building the text another way, for example with TEXTJOIN.
REPT always returns text. A repeated "0" such as "000" is not the number 0. Wrap the result in VALUE if you need a number.
"|", "-" or "0". It can be several characters long.0 returns an empty string. A negative number returns #VALUE!.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
C2 =REPT("-",20)
Result: --------------------
Twenty dashes. Change the second argument to change the length.
C2 =REPT("-",20) returns --------------------
Example 2
C3 =REPT("|",B3/10)
Result: |||||||
One bar character for every 10 units. The formula in C2 would give four bars, and C4 two.
C3 =REPT("|",B3/10) returns |||||||
Example 3
C2 =REPT("0",8-LEN(A2))&A2
Result: 00000412
The ID has 3 characters, so 8 - 3 = 5 zeros are added in front. The result is text.
C2 =REPT("0",8-LEN(A2))&A2 returns 00000412
Example 4
C2 =REPT("*",LEN(A2)-4)&RIGHT(A2,4)
Result: ******7712
REPT supplies one asterisk per hidden character, and RIGHT adds the last four. It works for accounts of any length over four.
C2 =REPT("*",LEN(A2)-4)&RIGHT(A2,4) returns ******7712
Solve it in the sheet. Every answer is checked, with hints if you need them.
Task 1 of 2
In C2, draw a bar of | characters with one | for every 10 units in B2. Fill it down to C5. The units are multiples of 10.
Answer in C2, then it fills down to C5.
=REPT("|",2.9) gives two bars. Use ROUND if you want normal rounding.#VALUE!. In a padding formula such as REPT("0",8-LEN(A2)), an ID longer than 8 characters makes the count negative.|, look different between fonts and sizes. Check the result in the font you will use.#VALUE!.Use REPT with a bar character and a count based on the value, for example `=REPT("|",B2/10)`. For a graphic version, use conditional formatting data bars instead.
For text IDs, use `=REPT("0",8-LEN(A2))&A2`. For numbers, `=TEXT(A2,"00000000")` is shorter.
REPT has no separator option. Put the separator in the text and remove the extra one at the end, or use TEXTJOIN with a sequence of identical items.
Zero returns an empty string. A negative number returns `#VALUE!`.
A cell holds at most 32,767 characters, so a result longer than that returns `#VALUE!`.
Tracks take you from the basics to modelling, one graded exercise at a time.