我试图根据触发词" order"将一行数据从一个工作表(IT库存)移动到另一个工作表(InventoryAllocation)。在“操作”列中。当数字变为0时,Action列变为ORDER ...这有效:
但我也想让整行移到第二张(InventoryAllocation)并从第一张纸上删除它。
我的问题是我应该在脚本中更改哪些变量/声明,因为我尝试了各种变量/声明并继续收到错误:
TypeError:无法读取属性" source"来自undefined。 (第6行,文件"代码")
这是我正在使用的脚本:
/**
* Moves row of data to another spreadsheet based on criteria in column 5 to sheet with same name as the value in column 6.
*/
function onEdit(e) {
var ss = e.source;
var s = ss.getActiveSheet();
var r = e.range;
// The code below logs the ID for the active spreadsheet.
Logger.log(SpreadsheetApp.getActiveSpreadsheet().getId());
// to let you modify where the action and move columns are in the form responses sheet
var actionCol = 5;
var nameCol = 6;
// Get the row and column of the active cell.
var rowIndex = r.getRowIndex();
var colIndex = r.getColumnIndex();
// Get the number of columns in the active sheet.
// -1 to drop our action/status column
var colNumber = s.getLastColumn()-1;
// if the action/status col is changed to ok do stuff. Change "ok" below to whatever you want the trigger word to be.
if (e.value == "ORDER" && colIndex == actionCol) {
// get our target sheet name - in this example we are using the Skin Type column
var targetSheet = s.getRange(rowIndex, nameCol).getValue();
// if the sheet exists do more stuff
if (ss.getSheetByName(targetSheet)) {
// set our target sheet and target range
var targetSheet = ss.getSheetByName(targetSheet);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
// get our source range/row
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
// new sheets says: 'Cannot cut from form data. Use copy instead.'
sourceRange.copyTo(targetRange);
// ..but we can still delete the row after. Put // in front of below row if you don't want to delete after copying to new sheet
s.deleteRow(rowIndex);
// or remove // below if you want to keep but note the move, but you'll need to add // to row above if removing // from below
// r.setValue("Copied");
}
}
}
非常感谢任何帮助。
谢谢!