4

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!

2
  • If you have the desired column number in an extra row you could sort by row (transpose, sort by column, transpose)
    – Steve
    Commented May 16, 2017 at 9:06
  • 1
    =QUERY(A:D, "SELECT D, C, B, A") Commented May 16, 2017 at 10:31

1 Answer 1

4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.