Skip to content

Instantly share code, notes, and snippets.

@mrjarbenne
Created May 29, 2018 17:31
Show Gist options
  • Save mrjarbenne/a82fde29a7ecfbe9a3279ba6a13492eb to your computer and use it in GitHub Desktop.
Save mrjarbenne/a82fde29a7ecfbe9a3279ba6a13492eb to your computer and use it in GitHub Desktop.
Move a row in a Google Sheet from one sheet to another: Props https://productforums.google.com/forum/#!topic/docs/ehoCZjFPBao
function onEdit() {
// moves a row from a sheet to another when a magic value is entered in a column
// adjust the following variables to fit your needs
// see https://productforums.google.com/d/topic/docs/ehoCZjFPBao/discussion
var sheetNameToWatch = "COMMUNICATIONS";
var columnNumberToWatch = 5; // column A = 1, B = 2, etc.
var valueToWatch = "DONE";
var sheetNameToMoveTheRowTo = "ARCHIVE";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
if (sheet.getName() == sheetNameToWatch && range.getColumn() == columnNumberToWatch && range.getValue() == valueToWatch) {
var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
sheet.getRange(range.getRow(), 1, 1, sheet.getLastColumn()).moveTo(targetRange);
sheet.deleteRow(range.getRow());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment