Skip to content

Instantly share code, notes, and snippets.

/what.js
Created Jul 9, 2015

Embed
What would you like to do?
function checkForCompletion(event) {
// assumes source data in sheet named Needed
// target sheet of move to named Acquired
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
// Ignore edits on sheets other than the first sheet
if (s.getName() !== 'Sheet1') { return; }
// Column 10 refers to column J (labeled 'Notes')
if (r.getColumn() !== 10) { return; }
// Ignore values that don't begin with 'finished'
var finishedRegex = new RegExp("finished.*", "i");
if (!finishedRegex.test(r.getValue())) { return; }
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Complete");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
function registerEvent() {
var sheet = SpreadsheetApp.getActive();
ScriptApp.newTrigger("checkForCompletion")
.forSpreadsheet(sheet)
.onEdit()
.create();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.