Avishay28
Avishay28

Reputation: 2456

Reorder/reverse column order

I want to change the columns order in google sheet from this:

enter image description here

To this enter image description here

I know I can do this manually but if I have a lot of columns it's pretty annoying. There's a simple way to do this? Thanks in advance!

Upvotes: 4

Views: 2140

Answers (1)

ttarchala
ttarchala

Reputation: 4557

Building on the idea proposed by Steve in the comment. This works for any arbitrary range, pasted as tested on a range of columns A to D:

=array_constrain(
  transpose(sort(transpose({A:D; arrayformula(column(A:D))}), rows(A:D)+1, false)),
  rows(A:D),
  columns(A:D)
 )

Explanation: the 1st argument does the inversion magic by inserting a row of column numbers, transposing, sorting by this row in descending order and transposing back. Then we get rid of this extra row by constraining the result to the original dimensions.

The formula works and is generic enough, but it still feels like a hack. I wonder if someone can come up with a cleaner solution.

Upvotes: 4

Related Questions