Google Sheet: How to return array data in a horizontal way?
Asked Answered
F

2

5

I write a custom function in Google Sheet:

function array_test() {
  return [1,2];
}

And test it in Google Sheet =array_test(): enter image description here

You can see Google Sheet expands array data in a vertical way. But I just want to Google Sheet expands array data in a horizontal way, like that:

enter image description here

So, could anyone please give me some suggestion about that?

Faceplate answered 20/1, 2020 at 4:43 Comment(0)
A
6
  • You want to put the returned values from the custom function to the column direction.

If my understanding is correct, how about this modification?

From:

return [1,2];

To:

return [[1,2]];
  • When 1 dimensional array is used as the returned values, the values are put to the row direction.
  • When 2 dimensional array is used as the returned values, the values are put to the row and column direction.
  • For example, when [["a1", "b1"], ["a2", "b2"]] is returned to the cell "A1", the values are put to "A1:B2".

Reference:

If I misunderstood your question and this was not the result you want, I apologize.

Agnola answered 20/1, 2020 at 4:49 Comment(0)
C
1

If you apply the TRANSPOSE formula to your result, it gives you a script-free way to do this. Not sure if you needed to do your work in code to begin with, this is a simple alternative.

Charismatic answered 28/5, 2023 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.