2020年12月20日星期日

Google sheet + Apps script: faster then for loop

Hi I'm using this code to loop trough another google worksheet find in column 'B' the id number 'idNum' once the id number is found the script replaces the whole row with new data but it seem to be taking a long time before the following script get triggered is there a way to make it faster to loop though or to make the next script trigger faster. here's my code Thanks

  function editRow(){            var mainsheet = ('10_XEaQiR71----- Sheet ID ----uOhi9VVtk5FI')      var tsheet = SpreadsheetApp.openById(mainsheet).getSheetByName('Data')      var targetSheet1 = tsheet.getDataRange().getValues()      var sheet = SpreadsheetApp.getActive();      var sourceData = sheet.getSheetByName('Data Input').getRange('A2:IB2').getValues()[0];      var idNum = sheet.getSheetByName('Data Input').getRange ("B2").getValue();      var copyFrom = sheet.getSheetByName('Data Input').getRange('A2:IB2')      var data = copyFrom.getValues()          for(var i = 0; i<targetSheet1.length;i++){        if(targetSheet1[i][1] == idNum){           var row = i=i+1          tsheet.getRange('A'+row+':IB'+row).setValues(data);                   break;           }         }        next script       }  
https://stackoverflow.com/questions/65378239/google-sheet-apps-script-faster-then-for-loop December 20, 2020 at 04:40PM

没有评论:

发表评论