I have a Google Sheet with a specific number of rows, and I want to use a script/macro to move a certain row to the very bottom.
const DESTINATION_INDEX = 4;
function myFunction() {
const ss = SpreadsheetApp.getActive();
const foo = ss.getRangeByName('foo');
foo.getSheet().moveRows(foo, DESTINATION_INDEX);
}
That causes it to end up at row 3 (as the moveRows()
documentation and example suggest):
But when DESTINATION_INDEX = 5
, it throws Exception: Those rows are out of bounds.
I could work around this by moving foo
to the penultimate row, then moving the last row up by one. Or I could do a little insertRowAfter
/deleteRows
dance.
But is there any way to move a row directly to the bottom? This seems like an oversight in the API.
the data may end up at a different index than originally specified.
What is the point of that? You nominate row#4, row#4 exists, yet it doesn't move the row to row #4, it moves it to Row#3 instead! My preference would be that they delete this function and start over.