I have been trying to run this code on Google scripts but running into the following error -TypeError: Cannot call 'getRange' method of null ('code' file, line 5)
The code is below. Any help is truly appreciated.
Thanks!
function myFunction() {
var d = new Date();
var hours = d.getHours();
var currentTime = d.toLocaleDateString();
var counter = SpreadsheetApp.getActiveSheet().getRange('B1').getValues();
if (hours >= 6 && hours <= 18) {
var response = UrlFetchApp.fetch("url");
SpreadsheetApp.getActiveSheet().getRange('S' + counter).setValue('Visted at ' + currentTime + ' ' + hours + 'h');
SpreadsheetApp.getActiveSheet().getRange('B1').setValue(Number(counter) + 1);
}
}