Web Applications Stack Exchange is a question and answer site for power users of web applications. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an easy way to reverse the order of selected rows? (Or how about all rows, if that's easier.)

Specifically, in this case, there is no column that could be used for sorting to get them in right order. So, given a bunch of rows in an arbitrary order, is it possible to reverse that order?

As an example...

enter image description here

...after reversal of these 5 rows, "Waitrose 756" should come first and "Moot" last.

share|improve this question
up vote 14 down vote accepted

To reverse the order of the selected range (as opposed to sorting by a specific column), you could use the following script:

function reverseOrder()
  var range = SpreadsheetApp.getActiveRange();
  var values = range.getValues();

Adding this onOpen script will create a menu item called Extra, containing an item called Reverse:

function onOpen ()
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menu = [{name: "Reverse", functionName: "reverseOrder"}];
  ss.addMenu("Extra", menu);
share|improve this answer
Thanks. It took me a moment to figure out how to add these so that the menu item appears (Tools -> Script manager...), but once I got that done, it does work! – Jonik Jul 4 '13 at 13:48
@AdamL, How can we do this without scripting? – Pacerier Aug 21 '14 at 11:14
@AdamL: Great for moving text, but it fails to move cell background color etc. How can the script be extended to also perform this? – Gruber Feb 23 at 11:43
@Pacerier: apologies for the extraordinarily late reply, but one solution would be with a helper column with numbers in ascending order, and sort the range by that column descending (and then you can remove the helper values). – AdamL Feb 25 at 23:19
@Gruber: first option would be for the script to copy/paste one cell at a time; the second option would be to get all the required formats for the range, reverse them as well, and set them. I'd say the first option might be OK for small ranges, but terrible for large ranges; the second option would be the best bet to cover all use cases. – AdamL Feb 25 at 23:23

Here's an example of how to do this without using scripts - please note that this method assumes your data is just data - it might do strange things if you have formulas referencing other cells in the same range:

  1. Insert a new column (for the sake of example, we'll call it column A).
  2. In A1, put the value [1]. (You can start at A10, or A50 if you only want to sort a range)
  3. In A2, put the formula [= A1 + 1]. (Adjust if you didn't start at A1 in step 2)
  4. Extend the formula in A2 to the bottom of the data you wish to reverse.

    Everything should now be numbered from 1 to the number of rows in the range you're sorting.

  5. Select all rows in the range you've set up.
  6. Click on the Data menu, and select "Sort range by column A, Z -> A".

Your data should now be reversed order. Because of the way we set up the numbering formula, the number will get reset, and still start from 1 at the top... but the actual data in other columns should all be reversed.

share|improve this answer

Following Mir's example you may place SORT function into say cell D3 to reverse order for data in column C:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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