Is there a Google Sheets function to squeeze a range into one column?

有些话、适合烂在心里 提交于 2020-12-13 04:34:49

问题


I wanted to find the built-in function for this to no avail so I had to write it in script:

function squeeze(range) {
  return [].concat(...range).filter(n => n)
}

This JS function flattens the 2D array range and returns it.

Note that it filters out empty cells with uneven columns.


回答1:


While not officially documented (yet), flatten() also exists as a built-in formula. See here for more info.




回答2:


if FLATTEN gets removed by some evil google dude you can do:

=TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(A1:C3),,9^9)),,9^9), " "))

E1:   =FLATTEN(A1:C3)



回答3:


Thanks to JPV and based on his answer, I added FILTER to leave out empty cells:

=FILTER(FLATTEN(B2:L7), FLATTEN(B2:L7)<>"")

Plus TRANSPOSE, I didn't specify this but I wanted multiple columns into one, not multiple rows into 1 column.

=FILTER(FLATTEN(TRANSPOSE(B2:L7)), FLATTEN(TRANSPOSE(B2:L7))<>"")


来源:https://stackoverflow.com/questions/63280316/is-there-a-google-sheets-function-to-squeeze-a-range-into-one-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!