Is there a way to use sheet functions like SUM, SUMIF, COUNTIF, COUNA etc in Google Apps Scripts to automate ?
Asked
Active
Viewed 123 times
-1
-
3Does this answer your question? [How to call a Google Sheet formula from within a custom function?](https://stackoverflow.com/questions/61390574/how-to-call-a-google-sheet-formula-from-within-a-custom-function) – TheMaster May 29 '20 at 22:04
1 Answers
2
It's rather easy to combine them all into your scripts since it just requires a little logic. You can play with this by selecting a range and then executing the function and the results are displayed on a toast.
function sumandcount() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var rg=sh.getActiveRange();
var values=rg.getValues();
var sumifgtr5=0;
var countifgtr5=0
values.forEach(function(r,i){
r.forEach(function(c,j){
if(c>5) {
sumifgtr5+=c;
countifgtr5+=1;
}
})
});
var obj={count:countifgtr5,sum:sumifgtr5};
ss.toast(obj.count, obj.sum);
}

Cooper
- 59,616
- 6
- 23
- 54