I am trying to create a JavaScript loop for gmail spreadsheets that counts the cells that have the yesterday date and give the sum in a different cell. I know I can do it through excel or in the spreadsheet but I prefer doing it through the script editor (I am newbie). Here is my code:
function job_counter(k) {
var row = k.range.getRow();
var col = k.range.getColumn();
var yesterday_jobs = 0;
var today = new Date();
today;
console.log(today)
var yesterday = today - 1
yesterday;
console.log(yesterday)
for (var i = 1; i < 25; i++){
if (col === 3 && row === i && k.source.getActiveSheet().getRange(row,col).getValue() === yesterday)
yesterday_jobs === yesterday_jobs+1;
console.log(yesterday_jobs);
k.source.getActiveSheet().getRange(16,1).setValue(yesterday_jobs);
} // check yesterday_jobs
}
It does not seem to work plus I get the message
TypeError: Cannot read property "range" from undefined. (line 3, file "Code"
that should not be a problem.