Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a range repeat n-times in Google SpreadSheet

Tags:

I use ArrayFormula() to simplify the way I create my reports.

Instead of having to create a reference in each cell (eg. =C1,=C2,=C3,=C4 in each cell, I just use =arrayformula(C1:C4) in one single cell. It does exactly same job, but is much simpler and it keeps things more organized, because I just need to look in one cell for possible errors.

It works great when I have to reference a range into another like take the values of C1:C4 into the A1:A4 range. In the A1 cell I would just write =arrayformula(C1:C4) and it does its magic.

It does get a bit trickier when the ranges are not the same length, but it is feasible nonetheless. For instance, if I want to stack two or more range link C1:C4 on top of B1:B3, on cell A1 I can write =arrayformula({C1:C4;B1:B3}).

My problem is using arrayFormula() to copy a repeating pattern. For instance, if I want to copy the content of cell C1 4 times I would use =arrayformula({C1;C1;C1;C1}).

This would work and would achieve the desired effect. However, I was wondering if there is a better way to do that. Something like =arrayformula({C1}*12) were this pattern would repeat 12 times. This would also enable me to have a dynamic formula, such as =arrayformula({C1}*count(D:D)) where the pattern would repeat according to some variable.

Do you have any ideia on how to achieve that using only native formula (no javascript)?

like image 941
user3347814 Avatar asked Jan 27 '16 12:01

user3347814


People also ask

How do I make a repeating pattern in Google Sheets?

Start a pattern in a range of cells, highlight those cells, then grab the little blue corner box of the highlighted range and pull. The pattern will repeat to whatever range of cells you extend the highlighting over.

Is there a repeat function in Google Sheets?

The REPT function in Google Sheets is used to repeat an expression a set number of times. Notice the additional space added after the exclamation point, so that there is a space between the repeated values in the output.


1 Answers

I would use split() function instead of arrayformula() and rept() function to repeat cell positions. For example, if your n=4 the formula will look like this:

=split(rept(C1&";",4),";") 

rept() repeats cell position C1+semicolon four times creating a string and split() function divides created string by semicolons to horizontal cells.

You can rotate resulted horizontal table to vertical table using transpose() function:

=transpose(split(rept(C1&";",4),";")) 

And yes, you can use it to create dynamic formulas with help of arrayformula() function:

=arrayformula(count(D:D)*split(rept(C1&";",4), ";")) 
like image 94
G4mo Avatar answered Nov 22 '22 21:11

G4mo