Skip to content

Instantly share code, notes, and snippets.

@shinchiro
Last active December 2, 2016 21:05
Show Gist options
  • Save shinchiro/a8d3a609ebae102580192f49e1ecc294 to your computer and use it in GitHub Desktop.
Save shinchiro/a8d3a609ebae102580192f49e1ecc294 to your computer and use it in GitHub Desktop.
Google Spreadsheet scripts
// Reference: http://webapps.stackexchange.com/a/31942
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Data" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
var last = s.getLastColumn() - r.getColumn();
var nextCell = r.offset(0, last);
var time = new Date();
time = Utilities.formatDate(time, "GMT", "dd-MM-yyyy");
nextCell.setValue(time);
};
}
// http://stackoverflow.com/a/15863007
// http://webapps.stackexchange.com/a/25570
function onOpen() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Data" ) { //checks that we're on the correct sheet
// // assumes headers in row 2
var range = s.getRange(3, 1, s.getLastRow()-2, s.getLastColumn());
range.sort({column: 13, ascending: false});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment