REPT Function in Excel

Part 1: Introduce

💡 Definition: The REPT function in Microsoft Excel is a text function that repeats a specific text string several times. It allows you to create a new text string by repeating the original text.

🎯 Purpose: The purpose of the REPT function is to generate repetitive text patterns or structures in Excel. It is beneficial for creating visual elements, such as borders or dividers, and generating placeholder values or dummy data.

📚 Syntax & Arguments: The syntax of the REPT function is as follows:

syntax
=REPT(text, number_times)
  • text: This is the required argument representing the text string you want to repeat.
  • number_times: This is the required argument specifying the number of times you want them text repeated.

🔍 Explain the Arguments in the function:

  • text: It can be either a text string enclosed in double quotation marks (“”) or a reference to a cell containing the text you want to repeat.
  • number_times: It specifies the number of times you want them text to be repeated. It should be a positive integer.

💡 Return Value: The REPT function returns a new text string that consists of  text repeated number_times times.

📝 Remarks:

  • The total length of the resulting text string is determined by the length of the text multiplied by the number_times.
  • If number_times is less than or equal to zero, the REPT function returns an empty string.
  • The REPT function is commonly combined with other functions, such as CONCATENATE or SUBSTITUTE, to generate complex text patterns or structures.

Part 2: Examples

Let’s explore three examples that demonstrate the usage of the REPT function:

1️⃣ Example 1: Creating a Border

AB
1DataBordered Data
2John=REPT(“-“, 20) & A2 & REPT(“-“, 20)
3Lisa=REPT(“-“, 20) & A3 & REPT(“-“, 20)

In this example, we have data in column A and want to create a border around each data entry. The REPT function is used in column B to generate the edge.

  • The formula =REPT("-", 20) & A2 & REPT("-", 20) in the cell, B2 generates a border of hyphens (“-“) by repeating it 20 times. The frame is then concatenated with the data in cell A2 and another wall, resulting in a bordered entry.
  • Similarly, the formula =REPT("-", 20) & A3 & REPT("-", 20) in cell, B3 generates a border around the data in cell A3.

2️⃣ Example 2: Creating Dummy Data

AB
1HeaderDummy Data
2Item=REPT(“Item “, 5)
3Quantity=REPT(“10 “, 3)
4Price=REPT(“$99.99 “, 2)

In this example, we have headers in column A, and we want to generate dummy data for testing or placeholder purposes. The REPT function is used in column B to create the dummy data.

  • The formula =REPT("Item ", 5) in cell B2 repeats the text “Item ” five times, generating the dummy data “Item Item Item Item Item “.
  • The formula =REPT("10 ", 3) in cell B3 repeats the text “10 ” three times, creating the dummy data “10 10 10 “.
  • Similarly, the formula =REPT("$99.99 ", 2) cell B4 repeats the text “$99.99 ” twice, resulting in the dummy data “$99.99 $99.99 “.

3️⃣ Example 3: Creating a Pyramid Structure

AB
1LevelPyramid
21=REPT(” “, 5 – A2) & REPT(“* “, A2)
32=REPT(” “, 5 – A3) & REPT(“* “, A3)
43=REPT(” “, 5 – A4) & REPT(“* “, A4)

In this example, we have levels in column A, and we want to create a pyramid structure using asterisks. The REPT function is used in column B to build the pyramid.

  • The formula =REPT(" ", 5 - A2) & REPT("* ", A2) cell, B2 generates spaces (” “) based on the difference between 5 and the level number in A2. It then repeats the asterisk and a space pattern (“* “) based on the level number, creating the pyramid structure.
  • Similarly, the formulas =REPT(" ", 5 - A3) & REPT("* ", A3) in cell B3 and =REPT(" ", 5 - A4) & REPT("* ", A4) in cell B4, generate the pyramid structure for levels 2 and 3, respectively.

4️⃣ Example 4: Creating a Progress Bar

AB
1TaskProgress Bar
2Task A=REPT(“█”, A2) & REPT(“-“, 10 – A2)
3Task B=REPT(“█”, A3) & REPT(“-“, 10 – A3)
4Task C=REPT(“█”, A4) & REPT(“-“, 10 – A4)

In this example, we have tasks in column A and want to create a progress bar for each job. The REPT function is used in column B to generate the progress bar.

  • The formula =REPT("█", A2) & REPT("-", 10 - A2) cell B2 repeats the character “█” (full block) based on the value in cell A2, representing the progress. It then repeats the “-” (hyphen) character for the remaining spaces. This creates a progress bar with filled blocks and empty spaces based on the task progress.
  • Similarly, the formulas =REPT("█", A3) & REPT("-", 10 - A3) and =REPT("█", A4) & REPT("-", 10 - A4) in cells B3 and B4, respectively, generate progress bars for tasks B and C.

5️⃣ Example 5: Creating a Sales Chart

AB
1MonthSales Chart
2Jan=REPT(“▄”, A2) & REPT(” “, 12 – A2)
3Feb=REPT(“▄”, A3) & REPT(” “, 12 – A3)
4Mar=REPT(“▄”, A4) & REPT(” “, 12 – A4)

In this example, we have months in column A and want to create a visual sales chart using blocks. The REPT function is used in column B to generate the sales chart.

  • The formula =REPT("▄", A2) & REPT(" ", 12 - A2) in cell B2, repeats the “▄” (full block) character based on the sales value in cell A2, representing the sales volume. It then repeats the space character for the remaining months. This creates a monthly sales chart with filled blocks based on the sales volume.
  • Similarly, the formulas =REPT("▄", A3) & REPT(" ", 12 - A3) and =REPT("▄", A4) & REPT(" ", 12 - A4) in cells B3 and B4, respectively, generate sales charts for February and March.

6️⃣ Example 6: Formatting Numeric IDs

AB
1IDFormatted ID
212345=”ID-” & REPT(“0”, 8 – LEN(A2)) & A2
35678=”ID-” & REPT(“0”, 8 – LEN(A3)) & A3

In this example, we have numeric IDs in column A and want to format them with leading zeros. The REPT function is used in column B to create the formatted IDs.

  • The formula ="ID-" & REPT("0", 8 - LEN(A2)) & A2 cell B2 concatenates the string “ID-” with the repeated character “0” based on the difference between 8 and the ID length in cell A2. It then appends the ID itself. This creates a formatted ID with leading zeros, ensuring a consistent length of 8 characters.
  • Similarly, the formula ="ID-" & REPT("0", 8 - LEN(A3)) & A3 in cell, B3 formats the ID in cell A3 with leading zeros.

7️⃣ Example 7: Creating a Dot Matrix Pattern

AB
1PatternDot Matrix
21=REPT(“• “, A2) & REPT(” “, 8 – A2)
32=REPT(“• “, A3) & REPT(” “, 8 – A3)
43=REPT(“• “, A4) & REPT(” “, 8 – A4)

In this example, we have patterns in column A represented by numbers and want to create a dot matrix visualization of the ways. The REPT function is used in column B to generate the dot matrix.

  • The formula =REPT("• ", A2) & REPT(" ", 8 - A2) cell B2 repeats the “•” (dot) character followed by a space based on the value in cell A2, representing the pattern. It then repeats the space character for the remaining dots. This creates a dot matrix visualization of the way with filled dots and empty spaces.
  • Similarly, the formulas =REPT("• ", A3) & REPT(" ", 8 - A3) and =REPT("• ", A4) & REPT(" ", 8 - A4) in cells B3 and B4, respectively, generate dot matrix patterns for numbers 2 and 3.

8️⃣ Example 8: Formatting Phone Numbers

AB
1Phone NumberFormatted Phone Number
21234567890=”(” & LEFT(A2, 3) & “) ” & MID(A2, 4, 3) & “-” & RIGHT(A2, 4)
39876543210=”(” & LEFT(A3, 3) & “) ” & MID(A3, 4, 3) & “-” & RIGHT(A3, 4)

In this example, we have phone numbers in column A, and we want to format them in the standard format with parentheses and hyphens. The REPT function is not directly used in this example but can be combined with other text functions.

  • The formula ="(" & LEFT(A2, 3) & ") " & MID(A2, 4, 3) & "-" & RIGHT(A2, 4) cell B2 formats the phone number by extracting the first three digits using the LEFT function, followed by the next three digits using the MID function, and the last four digits using the RIGHT part. These components are concatenated with the desired formatting characters to create the formatted phone number.
  • Similarly, the formula ="(" & LEFT(A3, 3) & ") " & MID(A3, 4, 3) & "-" & RIGHT(A3, 4) in cell, B3 formats the phone number in cell A3.

9️⃣ Example 9: Creating a Star Rating

AB
1RatingStar Rating
23=REPT(“★”, A2) & REPT(“☆”, 5 – A2)
35=REPT(“★”, A3) & REPT(“☆”, 5 – A3)
42=REPT(“★”, A4) & REPT(“☆”, 5 – A4)

In this example, we have ratings in column A and want to create a star rating representation. The REPT function is used in column B to generate the star rating.

  • The formula =REPT("★", A2) & REPT("☆", 5 - A2) cell B2 repeats the “★” (black star) character based on the rating value in cell A2, representing the filled stars. It then repeats the “☆” (white star) character for the remaining spaces. This creates a star rating visualization with filled stars based on the rating.
  • Similarly, the formulas =REPT("★", A3) & REPT("☆", 5 - A3) and =REPT("★", A4) & REPT("☆", 5 - A4) in cells B3 and B4, respectively, generate star ratings for ratings 5 and 2.

🔟 Example 10: Generating a Barcode

AB
1CodeBarcode
212345=”[ ” & REPT(“
367890=”[ ” & REPT(“

In this example, we have codes in column A and want to generate a barcode representation. The REPT function is used in column B to create the barcode.

  • The formula ="[ " & REPT("| ", A2) & "]" in cell B2 surrounds the repeated character “| ” (vertical bar and space) based on the code value in cell A2 with brackets “[” and “]”. This creates a barcode-like representation using vertical bars.
  • Similarly, the formulas ="[ " & REPT("| ", A3) & "]" in cell B3 generate barcodes for the codes in cell A3.

Part 3: Tips and Tricks

Here are some tips and tricks related to the REPT function:

  1. The REPT function can be combined with others like CONCATENATE or TEXT to create more complex patterns or structures.
  2. To develop dynamic repetitions based on the length or value of a cell, you can use cell references within the REPT function. This allows you to adjust the repetitions easily by changing the referenced cell.
  3. When using the REPT function with wide characters (e.g., double-byte characters), remember that the resulting text may not align correctly due to differences in character widths.