Skip to content

Instantly share code, notes, and snippets.

@oshliaer
Last active February 12, 2018 20:26
Show Gist options
  • Save oshliaer/8ca63d4993da80e26774 to your computer and use it in GitHub Desktop.
Save oshliaer/8ca63d4993da80e26774 to your computer and use it in GitHub Desktop.
Google Apps Script
function onEdit() {
// moves a row from any sheet to an archive sheet when a magic value is entered in a column
var columnNumberToWatch = /* column Q */ 3; // column A = 1, B = 2, etc.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var as = SpreadsheetApp.getActiveSheet();
var cell = as.getActiveCell();
var track_val = cell.getValue().toUpperCase(); // If the names of sheets needed exactly skip .toUpperCase()
if (as.getName() !== track_val && cell.getColumn() == columnNumberToWatch) {
var targetSheet = ss.getSheetByName(track_val);
if(!targetSheet)
{
ss.toast(Utilities.formatString('The sheet with the "%s" name is not found', track_val), 'Toast');
return;
}
var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
as.getRange(cell.getRow(), 1, 1, as.getLastColumn()).moveTo(targetRange);
as.deleteRow(cell.getRow());
targetRange.activate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment