Google-sheets – Trigger when a cell value changed by formula

google sheetsgoogle-apps-script

This is my situation:

  • Spreadsheet is set to recalculate on change and every minute
  • One of my cells has a formula that pulls data from an API
  • The combination of the two makes my cell value change from time to time

I want to run a script once the value of this cell is changed.

I tried to use onEdit() but it seems to trigger only when a user changes a cell, not when a formula changes it value.

What would be the right trigger for that?

Best Answer

A trigger is not enough.

You have to set a way to record a base value. Then, among other alternatives, you could set a time-driven trigger that call a script that compares the current value to the base value, if they are not the same then update the base value and do the other things that you require when the formula calculated value changes, otherwise do nothing.

To record the base value, you could use an spreadsheet cell or the Google Apps Script Properties Service.