Search code examples
arrayssortinggoogle-sheetsmergegoogle-sheets-formula

Google Sheets: merge two columns in order and loop them


I'm not sure how to best describe this, but let's say I have the following two columns:

Column 1 Column 2
A X
B Y
C Z
D

I'm hoping to write a google sheets formula to make a continuous list like this, where the two columns are combined, and then repeat the lists infinitely (drag down):

Column 3
A
X
B
Y
C
Z
D
X (column 2 starts repeating here)
A (column 1 starts repeating here)
Y
B
Z
C
X (column 2 starts repeating here)
D
Y
A (column 1 starts repeating here)
...

I've tried various arraylist formulas, but nothing seems to get me what I need.


Solution

  • try:

    =LET(r, ROWS(A:A), s, SEQUENCE(r), ARRAY_CONSTRAIN(TOCOL(
     {ARRAY_CONSTRAIN(REDUCE(, s, LAMBDA(a, b, {TOCOL(A2:A, 1); a})), r, 1), 
      ARRAY_CONSTRAIN(REDUCE(, s, LAMBDA(a, b, {TOCOL(B2:B, 1); a})), r, 1)}, 1, ), r-ROW()+1, 1))
    

    enter image description here

    to cut it in the middle, change r-ROW()+1 to 15 for example