Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Spreadsheets Script Move Row

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?

like image 254
Zotoaster Avatar asked May 06 '15 08:05

Zotoaster


People also ask

How do I move an entire row in Google Sheets?

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.

How do you move an entire row in Google Docs?

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.


1 Answers

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"));
like image 132
Alan Wells Avatar answered Sep 29 '22 17:09

Alan Wells