4
votes

Just like you can manually drag a row and it'll rearrange the whole sheet when you release it, I want to be able to do this in a script, such as: sheet.moveRow(from, to);

Is this possible?

2

2 Answers

5
votes

You'll need to first get a reference to a range, then use the moveTo() method of the range. Google Documentation - moveTo()

This is the sample code from the documentation:

// The code below will move the first 5 columns over to the 6th column
 var sheet = SpreadsheetApp.getActiveSheet()
 sheet.getRange("A1:E").moveTo(sheet.getRange("F1"));
0
votes

of course you can do what Alan said, but I would use sheet.moveRows(Range rowSpec, Integer destinationIndex) : void

documentation