我有这个脚本适用于我的Google表格。当列b中的值更改为指定值时,整行将移动到另一个工作表。我希望能够指定多个值,将所有行发送到某个工作表。奖励将是(如果很简单)设置一个或多个变量将行移动到表2的位置,并且一个或多个变量将行移动到表3,
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 = "2018";
var columnNumberToWatch = 2; // column A = 1, B = 2, etc.
var valueToWatch = "Next Year";
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());
}
}
(信用:我没有写这个剧本,也不记得我在哪里找到它了)
答案 0 :(得分:1)
更改此行
var valueToWatch = "Next Year";
到
var valuesToWatch = ["Next Year", "Last year"] //add values to array
和
if (sheet.getName() == sheetNameToWatch && range.getColumn() == columnNumberToWatch && range.getValue() == valueToWatch) {
到
if (sheet.getName() == sheetNameToWatch && range.getColumn() == columnNumberToWatch && valuesToWatch.indexOf(range.getValue())>-1) {
看看是否有效?