PDA

View Full Version : Spread Sheet - Automatic Reset a Cell to 0 'Zero'



ijpbs
08-19-2021, 03:43 AM
Hi Team,

Kindly share a script to reset a specific cell value to zero '0'.

Currently am using below script, but its not working - Its getting reset in 5 secs itself


function myFunction() {
var sheet = SpreadsheetApp.getActive().getSheetByName('sheet1'); sheet.getRange('B2').setValue(0);
}
function createTimeDrivenTriggers() {
ScriptApp.newTrigger('myFunction')
.timeBased()
.everyMinutes(5)
.create();
}

arnelgp
08-19-2021, 04:41 AM
var bolTimer =false

function myFunction1() {
var sheet = SpreadsheetApp.getActive().getSheetByName('sheet1'); sheet.getRange('B2').setValue(0);
if (boltimer=false) {
bolTimer=true;
createMyTrigger();
}
}

function createMyTrigger() {
// Creates a trigger that runs 10 seconds
ScriptApp.newTrigger("myFunction1")
.timeBased()
.after(10000)
.create()

}

ijpbs
08-19-2021, 05:02 AM
Thanks for the reply and code.

Its getting reset on 40 secs itself, need atleast 5 mins. Even if i increased the range to 1000 , its getting reset in 40 secs

arnelgp
08-19-2021, 06:07 AM
maybe decrease 10000 (actually in millisec)

1000 millisec = 1 second

1000 ms per sec x 60 sec per min x 5 min = 300000

after saving close and re-open.

ijpbs
08-19-2021, 11:26 PM
Thank you, but its getting reset in 40 secs for any millisec(300000)

arnelgp
08-20-2021, 12:52 AM
check the sheet "setting", i think there is already another trigger event in placed.

ijpbs
08-20-2021, 04:30 AM
okay, Thank you