Home > Software design >  Using ArrayFormula with a Dynamic Number of Column Header Names
Using ArrayFormula with a Dynamic Number of Column Header Names

Time:03-19

My goal is to use ArrayFormula with the SPLIT() function, and name the headers of each column.

My problem is that the formula below only works when the number of headers declared exactly matches the first row's number of elements to split ie. if there are 3 elements being split on the first row, the formula needs 3 headers named (g1, g2, g3), but if any rows have more than 3 elements to split, it gives an error.

Is there a way to make the column header names dynamic in number, so that the number of elements to split can be, say, from 0-10? The elements to be split will always be separated by a comma and no spaces.

=ArrayFormula({"g1", "g2", "g3";if(A2:A="","",split(A2:A,","))})

link to example: enter image description here

If we can use the Orders column, it's as simple as:

=index(iferror({"g"&sequence(1,max(B:B));split(A2:A,",")}))

enter image description here

  • Related