I'm trying to get a piece of code to work when the spreadsheet is open. I added the onOpen script, set the script trigger to "when spreadsheet is open", and waited for....nothing happened. What am I doing wrong?
The script basically copies a row from one sheet to another based on the value of a cell. I want the script to copy all the rows that have the specified value to the next sheet only when the sheet
function onOpen(){
moveThisRow();
}
function moveThisRow(){
var sheetNameToWatch = "Sheet1";
var columnNumberToWatch = 7; // column A = 1, B = 2, etc.
var valueToWatch = "move it";
var sheetNameToMoveTheRowTo = "Sheet2";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
var fill = sheet.getActiveRange-2;
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());
}
}
Help!