As seen in the picture i have 2 sheets. I need the appscript code for the following.
Move to Done
is clicked, the checked rows should get appended to the Done
sheet.pending
sheet.I have crafted a solution that you may try to get your expected result.
How this code works:
To meet your requirements of having a custom menu
, please run the onOpen()
function
Completed code:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('New Menu')
.addItem('Move to Done', 'myFunction')
.addToUi();
}
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var pending = ss.getSheetByName('pending');
var completed = ss.getSheetByName('completed');
var pendingData = pending.getDataRange().getValues();
var values = [];
for (var i = pendingData.length - 1; i >= 0; i--) {
if (pendingData[i][0] === true) {
values.push([pendingData[i][1], pendingData[i][2], pendingData[i][3]]);
pending.deleteRow(i + 1);
}
}
completed.getRange(completed.getLastRow() + 1, 2, values.length, 3).setValues(values.reverse());
}
Sample output:
Reference: