HomeGoogle DocsSpreadsheetHow to Use the REPT Function in Google Sheets

How to Use the REPT Function in Google Sheets

Published on

The REPT function has many uses in Google Sheets though the core purpose is to repeat a specified character or string N times.

If you ask me for two real-life examples, two formulas come to mind.

I’ve used it with Vlookup to duplicate rows, and another instance is for creating a Percentage Progress Bar in Google Sheets.

In short, you may find the REPT function helpful when you use it with the functions such as Vlookup, Len, ArrayFormula, Countif, etc.

REPT Function Syntax and Arguments in Google Sheets

Syntax:

REPT(text_to_be_repeated, number_of_repetitions)

Arguments:

text_to_be_repeated – To specify the character or string that you want to repeat.

number_of_repetitions – A positive number specifying the number of times (n) to repeat the text_to_be_repeated.

Google Sheets says it’s limited to 32,000 characters (please refer to the official documentation here).

Both the above arguments can be cell references or hardcoded within the formula.

REPT Function Basic Examples in Google Sheets

First, see some basic examples of the REPT function in Google Sheets.

=rept("-",10)

It repeats the hyphen character ten times.

If you enter the hyphen in cell A1, use the formula below.

=rept(A1,10)

We can use characters directly within the formula or the Char function to convert Unicode numbers and use them.

The character code of the red question mark is 10067. You can use either of the below formulas to get it repeated thrice.

=rept("❓",3)

Or

=rept(char(10067),3)

As a side note, to get several characters, you can use the following ArrayFormula, Sequence, and Char combo in cell A1 in an empty column A.

=ArrayFormula(char(sequence(1000,1,10000)))

In the following example, I have combined two REPT formulas to return black and white stars.

REPT Function Basic Examples - Star Characters

I hope the formulas themselves are self-explanatory.

Practical Use

Other than the two real-life use cases of the REPT function in Google Sheets mentioned at the beginning of this tutorial, here are two more examples.

One example involves Countif and the other with Split and ArrayFormula combination.

Example 1 – Countif in number_of_repetitions

Here I have a list of participants in a painting competition.

You can see their participation status visualized in column G with the help of asterisks.

=rept("*",countif(B3:F3,"Y"))

text_to_be_repeated – *

number_of_repetitions – countif(B3:F3,"Y")

Countif in number_of_repetitions

In this example, the Countif counts the occurrences of “Y” in the range B3:F3. It returns 5 for the first row. So the REPT function repeats the “*” 5 times.

I’ve copy-pasted the formula down.

Split and ArrayFormula Combination with REPT

Sometimes we may want to repeat columns N times for printing purposes.

Assume we have generated barcodes for a few items in a column and want it to print N times.

In that case, we can use the REPT function to repeat the column.

The below basic example will give you an idea of using the REPT function in Google Sheets with Split and ArrayFormula combination.

=ArrayFormula(split(rept(A2:A7&";",4),";"))
REPT Function to Repeat Labels in Google Sheets

In the above example, the combination of functions repeats the text and numeric values in column A 4 times.

Formula Explanation:

First, see the REPT formula part.

=ArrayFormula(rept(A2:A7&";",4))

What does it do?

The above formula converts the source data similar to the below image.

Repeat without Split

Then, we used the Split function to split the text into multiple columns using “;” as the delimiter. That’s all.

I will be back with a few more advanced use of the REPT function in coming tutorials. I hope you have enjoyed this session.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

XLOOKUP in Excel: Working with Visible Rows in a Table

In Excel, the XLOOKUP function isn't inherently designed to exclusively work with visible rows;...

SUMPRODUCT Differences: Excel vs. Google Sheets

The core purpose of the SUMPRODUCT function remains consistent across both Excel and Google...

Sum Values by Month and Category in Excel

With the help of EOMONTH, UNIQUE, and SUMIFS functions in Excel, you can efficiently...

More like this

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.