Search code examples
arraysgoogle-sheetsgoogle-sheets-formulatransposeflatten

Split strings in a google sheet cell into multiple rows?


In this thread I got the correct answer, but when I delete the values in columns B and C there are no results

Question link

Here is the google sheets formula

=INDEX(IFERROR(SPLIT(FLATTEN(FLATTEN(
FILTER(A2:A; A2:A<>"")&"×"&TRANSPOSE(
FILTER(B2:B; B2:B<>"")))&"×"&TRANSPOSE(
FILTER(C2:C; C2:C<>""))), "×"))

INPUT

A B C
car red AA
train yellow BB
blue CC
DD

OUPUT

I want when I delete the values in B and C to have the result like below.

A
car
train

If I just delete the result in column C, I get the result with 6 rows like below.

A B
car red
car yellow
car blue
train red
train yellow
train blue

Solution

  • use:

    =INDEX(SPLIT(FLATTEN(FLATTEN(
     FILTER(A2:A, A2:A<>"")&     IF(LEN(TRIM(QUERY(B2:B,,9^9))),"×"&TRANSPOSE(
     FILTER(B2:B, B2:B<>"")), ))&IF(LEN(TRIM(QUERY(C2:C,,9^9))),"×"&TRANSPOSE(
     FILTER(C2:C, C2:C<>"")), )), "×"))
    

    enter image description here

    enter image description here

    enter image description here