How to create arrayformula sequence number separated by comma in google sheets

Viewed 341

How to create arrayformula sequence number separated by comma in google spreadsheets expected results is in column B

A B
5 1,2,3,4,5
2 1,2
3 1,2,3
2 Answers

How about the following sample formula?

Sample formula:

=JOIN(",",ARRAYFORMULA(ROW(INDIRECT("A1:A"&A1))))
  • When you use this formula, please put this to a cell "B1" and drag down it.
  • The flow of this formula is as follows.
    1. Create a1Notation of cells using "A1:A"&A1 using INDIRECT.
    2. Retrieve row numbers from the a1Notation using ROW.
    3. Join the row numbers with , using JOIN.

Result:

enter image description here

Note:

When you want to put all result values using one formula, unfortunately, I couldn't find the formula using the built-in functions. In that case, I would like to propose to a custom function as follows. When you use this, please copy and paste the following script to the script editor of Spreadsheet.

And, please put a formula of =SAMPLE(A1:A) to a cell "B1". By this, the result values are put to the column "B" using the values of column "A".

const SAMPLE = v => v.map(([e]) => e && !isNaN(e) ? [...Array(e)].map((_, i) => i + 1).join(",") : "");

References:

You can use TEXTJOIN() with SEQUENCE() function.

=TEXTJOIN(",",TRUE,SEQUENCE(A1))

You can also use this functions in desktop Excel365

Related