8

I have a column containing 3 rows and I want to be able to repeat those rows 5 times each.

Example

Name
Dog
Cat
Ball

Desired Output

Output
Dog
Dog
Dog
Dog
Dog
Cat
Cat
Cat
Cat
Cat
Ball
Ball
Ball
Ball
Ball

Here's what I have tried:

=TRANSPOSE(split(rept(join(";",A:A)&";",5),";"))

My attempt produces:

Output
Dog
Cat
Ball
Dog
Cat
Ball
Dog
Cat
Ball
Dog
Cat
Ball
Dog
Cat
Ball
TheMaster
  • 45,448
  • 6
  • 62
  • 85
Wes Foster
  • 8,770
  • 5
  • 42
  • 62

4 Answers4

11

Without splitting and joining and other string manipulations,

=ARRAYFORMULA(FLATTEN(IF(SEQUENCE(ROWS(A2:A4),5),A2:A4)))
  • A2:A4 The range to repeat
  • 5 Number of times to repeat
  • SEQUENCE to create a 2D array of numbers
  • IF to transpose a 1D array A2:A4 to a 2D array of size equal to the SEQUENCE array created
  • FLATTEN the 2D to 1D array.
A1 Name
A2 Dog
A3 Cat
A4 Ball
Output
Dog
Dog
Dog
Dog
Dog
Cat
Cat
Cat
Cat
Cat
Ball
Ball
Ball
Ball
Ball
TheMaster
  • 45,448
  • 6
  • 62
  • 85
8
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(
 REPT(A1:A3&"♠", 5), ,999^99), "♠"))))

0


=SORT(TRIM(TRANSPOSE(SPLIT(QUERY(ARRAYFORMULA(
 REPT(A1:A3&"♠", 5)), ,999^99), "♠"))), 1, 0)

0

player0
  • 124,011
  • 12
  • 67
  • 124
  • 1
    Did what you posted and it worked. Then, I narrowed it down to just `SORT()` and it still seemed to work great! Thanks for pointing me in the right direction – Wes Foster Apr 02 '19 at 18:39
  • 2
    @WesFoster note that JOIN is limited to 50000 characters – player0 Apr 02 '19 at 18:42
1

=transpose(split(join("~",ArrayFormula(rept({Balls}&"~",3))),"~"))

Where:

  • Range is the range of text to repeat
  • Reps is the number of repititions

Note if your text contains a ~ change all instances of "~" to another character

John AZ1
  • 177
  • 2
  • 9
0

here is another trick.

A1:A3 are dog, cat, ball repeated 4 times in my example.

=ARRAYFORMULA( FLATTEN(A1:A3 & SPLIT(REPT(" |",4),"|")))
buddemat
  • 4,552
  • 14
  • 29
  • 49