Cristofer Dorante
Cristofer Dorante

Reputation: 13

Google Sheets: Is there a way to make an Array for a sequence that grows to a repeat given number of times

I have managed to make this formula:

=IF(COUNTIF($A$1:A1,A1)=$B$1,A1+1,A1)

Is making an incremental list in the same column, starting with 01, and on cell B1 I am instructing how many times this number should repeat (up to 5 times per number). So, if I say repeat 2 times it looks like this:

Column A
1
1
2
2

How can I make it an Array Formula? I'm barely starting on Arrays so I'm just trying to learn as I go.

Upvotes: 1

Views: 861

Answers (3)

Harun24hr
Harun24hr

Reputation: 36975

Try Sequence() with ROUNDUP() function.

=ArrayFormula(ROUNDUP(SEQUENCE(B1*B1)/B1,0))

enter image description here

When enter 3:

enter image description here

Upvotes: 1

Mike Steelson
Mike Steelson

Reputation: 15328

Try this

=ARRAY_CONSTRAIN(arrayformula(query(flatten(split(rept("|"&A2:A,B2:B),"|")),"select * where Col1 is not null")),SUM(B2:B),1)

https://docs.google.com/spreadsheets/d/1qXy-hzWUnsUmAa-8aV5IHOyZABGD_h8ajICLwdyNge8/edit?usp=sharing

Upvotes: 1

Sergey
Sergey

Reputation: 1131

you can try to solve this with the following formula =ArrayFormula(flatten(if(SEQUENCE(1,C1),SEQUENCE(C2)))) but you should specify the value limit in cell C2 to which the numbers must increase, otherwise the formula will loop

enter image description here

Upvotes: 1

Related Questions