- You want to update the function of cell "A1" every specific interval time.
If my understanding is correct, how about this modification?
Modification points:
- In your script, OnEdit event trigger is used. In this case, when the cell is edited, the trigger is fired.
- I think that this might not be suitable for your situation.
- How about using the time-driven trigger?
- There are some misspellings in your script. By this, variables are not used, and several error occur.
When above points are reflected to your script, it becomes as follows.
Modified script 1:
function forceEval(){ // Modified
var sheetName = "test-r";
var cell = "A1";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName); // Modified
var orig = sheet.getRange(cell).getFormula(); // Modified
var temp = orig.replace("=", "?");
sheet.getRange(cell).setFormula(temp); // Modified
SpreadsheetApp.flush();
sheet.getRange(cell).setFormula(orig); // Modified
}
- After you modified the script, in order to execute the function of
forceEval()
every specific interval time, please install the time-driven trigger.
- In this script,
#NAME?
is displayed for an instant. If you don't want to do this, how about the following sample script?
Modified script 2:
function forceEval(){
var sheetName = "test-r";
var cell = "A1";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getSheetByName(sheetName).getRange(cell);
var formula = range.getFormula();
range.clearContent();
SpreadsheetApp.flush();
range.setFormula(formula);
}
Install time-driven trigger:
In order to install the time-driven trigger, you can manually install it.
Also you can install it using the script. The following script installs the time-driven trigger for the function of forceEval
. In this sample script, when setTrigger()
is run, the function of forceEval()
is run every 10 minutes. By this, the formula of the cell "A1" is updated every 10 minutes.
function setTrigger() {
var minutes = 10; // In this case, as a sample value, it's 10 minutes.
var functionName = "forceEval";
var triggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < triggers.length; i++) {
if (triggers[i].getHandlerFunction() == functionName && triggers[i].getTriggerSource() == ScriptApp.TriggerSource.CLOCK) {
ScriptApp.deleteTrigger(triggers[i]);
}
}
ScriptApp.newTrigger(functionName).timeBased().everyMinutes(minutes).create();
}
Reference:
If I misunderstood your question and this was not the direction you want, I apologize.