Explanation:
You have two goals:
Copy the rows in sheet [Overview] All_Cases
that contain "No" in column Y to the OPS_FUNNEL_new
sheet.
After the copy is done, change the "No" in sheet [Overview] All_Cases
to "Yes".
Three major improvements:
It is not recommended to iteratively call getRange
and setRange
, read best practices for more info.
You don't need a for loop and if statements to find the data that contains "No" in column Y. Instead you filter this data with one line of code:
const data = srcSheet.getDataRange().getValues().filter(r=>r[24]=='No');
Then, copy it to the target sheet with one line of code:
tarSheet.getRange(tarSheet.getLastRow()+1,1,data.length,data[0].length).setValues(data);
Solution:
function copy_to_OPS_FUNNEL() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const srcSheet = ss.getSheetByName("[Overview] All_Cases");
const tarSheet = ss.getSheetByName("OPS_FUNNEL_new");
const data = srcSheet.getDataRange().getValues().filter(r=>r[24]=='No').map(r => [r[0]]);
if (data.length>0){
tarSheet.getRange(tarSheet.getLastRow()+1,1,data.length,1).setValues(data);
srcSheet.getRange("Y2:Y"+srcSheet.getLastRow()).setValue("Yes");
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…