Search code examples
arraysgoogle-sheetssplitarray-formulastextjoin

Merging two or more "lists" in columns?


Trying to find a way to merge multiple lists while preserving the order the items are in, right-to-left, then top-to-bottom.

Example:

A B C
D E
F
G H

should become:

A
B
C
D
E
F
G
H

and not

A
D
F
G
B
E
H
C

I have found countless sites with people explaining how I can just stick one list to the end of the previous (as shown in the "and not" example), but that is precisely not what I'm searching for.

Potential duplicate entries don't matter.

Editable example sheet here.


Solution

  • Sample formula

    =TRANSPOSE(SPLIT(TEXTJOIN(",",TRUE,A3:C28),","))
    
    • In this case, your shared Spreadsheet is used as the sample values.

    • From your "Desired Output" in your shared Spreadsheet, I thought that you are using the range of "A3:C28". If you want to use the range of "A3:C29", please modify above formula.

    • Flow is as follows.

      1. All values are converted to a string using TEXTJOIN.
        • In this case, , is used as the delimiter. If , is included in the values, please change this.
      2. The string value is splitted for putting to each cell using SPLIT.
      3. The value is transposed using TRANSPOSE.

    Result:

    In this sample, the formula is put to the cell "F3".

    enter image description here

    Note:

    • If you want to remove the duplicated values, please use UNIQUE like =UNIQUE(TRANSPOSE(SPLIT(TEXTJOIN(",",TRUE,A3:C28),","))).

    References: