I would like to know if it's actually faster to...
-do value calculation directly within the scripts editor
OR
-run the script that outputs formulas into cells.
The following is what I currently have:
function recheck_qty(itemname){
var itemcell = findcellbyvalue(itemname);
var itemcellrange = SpreadsheetApp.getActive().getSheetByName('Inventory').getRange(itemcell);
var row = itemcell.substring(1);
var sold = checkqty_sold1(itemname);
SpreadsheetApp.getActive().getSheetByName('Inventory').getRange("D"+row).setValue("=SUM(F"+row+":"+row+","+sold+")");
}
function checkqty_sold1(item) {
var ss = SpreadsheetApp.getActive();
var allsheets = ss.getSheets();
var sold = "";
var count = 0;
for(var s in allsheets){
var sheet = allsheets[s];
var sheetname = sheet.getName();
if(count>0){
sold += ","
}
if(sheetname!='Inventory'){
sold += 'IF(count(FILTER('+sheetname+'!F2:F,'+sheetname+'!B2:B="'+item+'"))<=0,0,-SUM(FILTER('+sheetname+'!F2:F,'+sheetname+'!B2:B="'+item+'")))';
count++;
}
} // end of loop
return sold;
}
Previously, I was doing actual calculations for var sold and the value of "SUM(F"+row+":"+row". But I realize that the data actually take some time to populate into the cell. Could be due to all the getrange(), getsheets() functions that i'm calling.. but i'm not sure.
Changing to this current one, I was able to make it slightly faster but only at times. It does not always work as fast. Still take sometime to load.