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?
On your computer, open a spreadsheet in Google Sheets. Select the rows or columns to move. At the top, click Edit. Select the direction you want to move the row or column, like Move row up.
Move a row On your computer, open a document in Google Docs. Hover in the left column of a table. Point your cursor over Drag until a hand appears. Click and drag the row up or down to its new location.
Use the sheets.moveRows(Range, Integer)
method.
See documentation at: https://developers.google.com/apps-script/reference/spreadsheet/sheet#moveRows(Range,Integer)
There is also the moveTo()
method which can move either columns or rows.
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With