Search code examples
google-sheets-formulaarray-formulasliteralssplit-function

Getting error in split function inside array formula when using it with column title(array literal)


I am using these functions in my google sheets. With an array literal, I am getting an error when there are comma-separated inputs which need to be split but its working fine when there is only value in the K column. It's working fine without column title. Can someone explain the error in the first code?

={"Don't Edit this Column TargetGroup ID";Arrayformula(IFERROR(SPLIT(MainSheet!K2:K,",",TRUE, True),""))}

and

 =Arrayformula(IFERROR(SPLIT(MainSheet!K2:K,",",TRUE, True),""))

Solution

  • Try this one:

    ={
      "Don't Edit this Column TargetGroup ID", Arrayformula(SPLIT(REPT(",", COLUMNS(SPLIT(MainSheet!K2:K,",")) - 2), ",", True, False));
      Arrayformula(IFERROR(SPLIT(MainSheet!K2:K,","),""))
    }
    

    You had only one string value for the first raw in you array literal ({}), so it is only one column.

    Presumably, SPLIT found at least one comma and gave you a minimum of two column range which cannot be attached to that first row of yours (the header string) from the bottom as they do not match column-wise.

    This SPLIT(REPT(...), ...) gives a needed number of empty cells to append to the right of your header so the number of columns will match.


    If that is not the case then please provide a error message or, even better, share a sample sheet where this issued is reproduced.