I would like a script to move a row from one sheet to another (within the same workshop) based on a TIME TRIGGER rather than onEdit (because onEdit doesn't work with IMPORTRANGE).
I found a script that worked brilliantly on edit:
function onEdit(event) {
// assumes source data in sheet named Active
// target sheet of move to named Completed
// getColumn with condition is currently set to column 12 or L
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Active" && r.getColumn() == 12 && r.getValue() == "8") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Completed");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
and a few that could work on time triggers and then combined/manipulated them to get this:
function PushToCompleted() {
// assumes source data in sheet named TEST
// target sheet of move to named Test2
// getColumn with condition is currently set to column 12 or L
var sss = SpreadsheetApp.openById('19WFdvLlWE-oI0OT8c6uBmgu2jSvdX0upM9nobscn5G4');
var ss = sss.getSheetByName("TEST");
var r = ss.getDataRange();;
if(ss.getName() == "TEST" && r.getColumn() == 12 && r.getValue() == "8") {
var row = r.getRow();
var numColumns = ss.getLastColumn();
var targetSheet = sss.getSheetByName("Test2");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
I then went in to set up the time trigger to every minute. But it's not working- not on manual run nor with the every minute time trigger. I'm VERY new with scripts, so would imagine there's something wrong within the script.
Any ideas?
else
case just to test your function invocation where you would set some test value in a random cell of your choice? – Jenea Vranceanuif(ss.getName() == "TEST" && r.getColumn() == 12 && r.getValue() == "8")
will only fire under the following conditions: 1. the sheetss
has a nameTEST
(which it does) AND 2. the data range of sheetss
starts on columnL
(which it doesn't,r.getColumn()
will return1
as r is the data range of sheetss
). What are you trying to get from ranger
? Or from sheetss
? – Rafa Guillermo