【发布时间】:2019-11-30 11:56:44
【问题描述】:
此脚本不适用于以下文件
当第 21 列中的值 =Delivered 时,我使用此脚本将行移动到另一个工作表
我不是程序员,我试图了解脚本如何工作并将代码嵌入其他代码中
所以如果你能帮助我重写这个脚本以更快更好地工作
提前致谢
/*
**** Move a row onEdit determined by a specific Cell value***
*/
// Names of sheets
var destinationSheet = "Collate"
/* col: the column to watch,
* changeVal: what value you want to change,
* del: do you want to delete after the change?
*/
var check = {
"col":17,
"changeVal": "DELIVERED",
"del": true ,
};
/* What you want to paste into the other sheet.
* start: start column
* cols: how many columns you want to copy
*/
var pasteRange = {
"start": 1,
"cols": 35
};
function onEdit(e) {
var sheets = ['FOOD', 'PET', 'KIND', 'Campbell', 'Other Clients']
for (var i = 0; i < sheets.length; i++) {
var sheetName = sheets[i]
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
if (sheet != null) {
if(sheet.getName() === sheets){
//Get active cell
var cell = sheet.getActiveCell();
var cellCol = cell.getColumn();
var cellRow = cell.getRow();
if(cellCol === check.col){
if(cell.getValue() === check.changeVal){
//Select the range you want to export
var exportRange = sheet.getRange(cellRow,pasteRange.start,1,pasteRange.cols);
//Select the past destination
var pasteDestination = ss.getSheetByName(destinationSheet);
var pasteEmptyBottomRow = pasteDestination.getLastRow() + 1;
//Copy the row to the new destination
exportRange.copyTo(pasteDestination.getRange(pasteEmptyBottomRow,1),
SpreadsheetApp.CopyPasteType.PASTE_VALUES);
//If delete is true delete after copying
if(check.del){
sheet.deleteRow(cellRow);
};
};
};
};
};
};
};
【问题讨论】:
-
欢迎。您说“此脚本不适用于以下文件”。该脚本是否适用于任何文件?您提到 Column 21 (Column U) = "Delivered, but on sheet="Collate" ( the sheet to watch"),Column U 与“Delivered”无关。请说明您的问题与您提供的工作表有何关联。
标签: google-apps-script google-sheets