Search code examples
google-sheetsconcatenationtransposeflattentextjoin

Combine two cells' data in loop, number the list and skip line


I was wondering what the simplest approach would to be transform my data from column 1 and 2 to column 3.

column 1 column2 combined
monty, alice monty@gmail.com, alice@gmail.com 1. monty - monty@gmail.com
2. alice - alice@gmail.com
matt, bob, ann matt@gmail.com, bob@gmail.com , ann@gmail.com 1. matthew - matthew@gmail.com
2. bob - robert@gmail.com
3. ann - anglica@gmail.com

What I have so far is ="1."&A2&"-"&B2 but this obviously does not allow me to loop through each item, number them and skip lines.

Another idea I had is to unmatch the columns, and apply the formula =&A2&"-"&B2 but then I am lost on how to matched them up in a numbered fashion with line skips.


Solution

  • use:

    =ARRAYFORMULA(TRIM(REGEXREPLACE(FLATTEN(QUERY(TRANSPOSE(IF(IFERROR(
     SPLIT(A1:A5, ","))="",,SEQUENCE(1, COLUMNS(SPLIT(A1:A5, ",")))&". "&
     SPLIT(A1:A5, ",")&" - "&SPLIT(B1:B5, ",")&"×")),,9^9)), "× |×$", CHAR(10))))
    

    enter image description here