Fixing Value Putting by Custom Function of Spreadsheet using Google Apps Script

Gists

This is a sample script for fixing a value putting by a custom function of Spreadsheet using Google Apps Script. When a custom function is used, the value retrieved by the custom function of Spreadsheet is automatically updated by recalculating. So in the case that the value retrieved by the custom function is changed by the time, the value is also changed by automatically updating. In this sample script, I would like to introduce a method for fixing such values.

Flow:

When you use this script, please do the following flow.

Sample script:

function onEdit(e) {
  if (e.range.getFormula().toUpperCase() == "=FOO(TRUE)") {
    e.range.setValue(new Date());
  }
}

function foo() {
  return new Date();
}

Reference:

I think that this method will be able to be applied to various scenes.

 Share!