我的问题:
-
每当我在表中第6行以下的任何位置插入一行时,下面的脚本都会运行。
-
事情是…我下面有两个部分基本相同,但当我插入新行时,只有第1部分被触发。即使我完全删除了第1节,第2节也不会因在行6下方的任何位置插入新行而触发。
-
为什么第1节是通过插入新行而不是第2节来触发的?有什么区别?这种情况以前并没有发生过——插入新行不会触发两个脚本,我认为这是因为下面的if语句从未得到满足。
-
我如何才能让它在插入新行时不会触发以下部分?
function onEdit(e) { //This IF statement ensures that this onEdit macro only runs when columns 2-5, from row 5 and below is edited: if ( e.source.getSheetName() == "Today" && e.range.columnStart >= 2 && e.range.columnEnd <= 5 && e.range.rowStart >= 5 ) { var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var Today = spreadsheet.getSheetByName("Today"); var checkboxtest = e.range.getValue() //This variable is used in If statement below, to ensure the macro runs when the checkbox is checked. var Task_cellRow = e.range.rowStart //This variable is used to determine which row to edit. // Section 1 - THIS SCRIPT IS TRIGGERED WHEN I INSERT A ROW BELOW ROW 6 if (e.range.getColumn() == 3) { if (checkboxtest == true) { }else if(checkboxtest == false){ //This script is to show if the above if-statements were triggered (they are) Today.getRange('A2').setValue("column 3 script was triggered"); } } //Section 2 - THIS SCRIPT IS NOT TRIGGERED WHEN I INSERT A ROW BELOW ROW 6..... But as far as I can tell it is almost identical to the above. if (e.range.getColumn() == 4) { if (checkboxtest == true) { }else if(checkboxtest == false){ //This script is to show if the above if-statements were triggered (they are not) Today.getRange('A3').setValue("column 4 script was triggered"); } } } }
行上唯一的限制是e.range.rowStart必须大于4