简体   繁体   中英

Split column into range of rows

I have a cell like this:

1
2
3
4
5
6
7
8
9
10

I would like to sort the data from one column to become 2 rows of 5 columns using Google Sheets.

Does someone know how to do that?

The result should be:

1 2 3 4 5
6 7 8 9 10

The solution should work regardless of how many values there are in the string inside the cell. Assume the cell is G4. Here goes the formula:

={array_constrain(split(G4, " "), 1, columns(split(G4, " "))/2);
  transpose(sort(transpose(array_constrain(transpose(sort(transpose(split(G4, " ")), 1, false)), 1, columns(split(G4, " "))/2))))
 }

There are many ways to do that. One is:

=TRANSPOSE({OFFSET(A1,,,COUNTA(A:A)/2),OFFSET(A1,COUNTA(A:A)/2,,COUNTA(A:A)/2)})

在此处输入图片说明

More general solution

To split the column into any given number of rows, use the formula:

=ArrayFormula(IFERROR(VLOOKUP( COLUMN(OFFSET(A1,,,1,ROUNDUP(COUNTA(A:A)/numRows)))+ ROUNDUP(COUNTA(A:A)/numRows)*(ROW(INDIRECT("a1:a"&numRows))-1), {ROW(A:A),A:A},2,)))

where numRows is a number of rows.

This:

COLUMN(OFFSET(A1,,,1,ROUNDUP(COUNTA(A:A)/numRows))) + ROUNDUP(COUNTA(A:A)/numRows)*(ROW(INDIRECT("a1:a"&numRows))-1)

generates indexes:

1   2   3   4
5   6   7   8
9   10  11  12
13  14  15  16

and VLOOKUP(indexes,{ROW(A:A),A:A},2,) is to return the result:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM