Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

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

2 Answers 2

up vote 9 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();
  range.setValues(values.reverse());
}

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 at 11:14

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

Your Answer

 
discard

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.