Skip to content

Instantly share code, notes, and snippets.

@phillypb
Created December 14, 2018 19:48
Show Gist options
  • Save phillypb/61b78e942a41abc4585e277bf0817672 to your computer and use it in GitHub Desktop.
Save phillypb/61b78e942a41abc4585e277bf0817672 to your computer and use it in GitHub Desktop.
function archiveData() {
// get active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// get source sheet by name
var sourceSheet = ss.getSheetByName('Students');
// get destination sheet by name
var destSheet = ss.getSheetByName('archive');
// find current Row on source sheet
var currentRow = sourceSheet.getActiveCell().getRow();
// get number of Columns with data in
var numCols = sourceSheet.getLastColumn();
// get current Row of data, getRange(startRow, startColumn, numRows, numColumns)
var data = sourceSheet.getRange(currentRow, 1, 1, numCols).getValues();
Logger.log(data);
// append to destination sheet
destSheet.appendRow(data[0]);
// delete current row on source sheet
sourceSheet.deleteRow(currentRow);
}
function onOpen() {
// add a custom menu to the spreadsheet
SpreadsheetApp.getUi()
.createMenu('Custom Menu')
.addItem('Archive data', 'archiveData') // label for menu item, name of function to run.
.addToUi();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment