Skip to content
Advertisement

Google sheets automatic Notes [with onEdit() function] on cells’ values resulting from formulas

Is it possible to create automatic Notes based on cells variable values resulting from formulas ?

For example A1=stxt(B1;1;4) gives “some” with B1=sometext (variable value), so that A1’s Note would be “some” And a second question : how to add at least a third condition for exceptions treatment in

JavaScript

I didn’t neither succeed having many OR conditions in one single code line so that I have to put many if statements like here :

JavaScript

PS : These questions come from my previous one answered here : Google sheets – Optimisation of function to create notes in a range (very slow)

Here’s an illustrating sheet : https://docs.google.com/spreadsheets/d/1xj5PMIQxvTNhq1gNiFf5SOwzxTH5LtY-NkHydU8Ptuk/edit?usp=sharing

Advertisement

Answer

onEdit() function which is only effective when cells values are manually edited but not by relative values changed by a function inside that cells

  • You are trying to trigger an onEdit function via a formula but that’s not how triggers work. The official documentation states the following:

The onEdit(e) trigger runs automatically when a user changes the value of any cell in a spreadsheet.

Namely, onEdit triggers are activated only by user actions, not by formulas nor scripts.

The workaround would be to modify the current onEdit code a little and include a code which will allow you to edit the formulas part when you change the value of the cells that the formula depends on. For example, you will set a note in a cell in column C of the Feuille1 sheet when you edit a cell in the same row in column A of Header 3:

JavaScript

Solution:

JavaScript

Also in your code you had if (NomFeuilleActive = "Feuille1") with one = (assignment operation) but this evaluates always to true and your code would be executed for any sheet name. I adjusted it to == which is the equality operator and the proper way to compare two variables.


how to add at least a third condition for exceptions treatment?

If you want to exclude many values and have multiple exceptions, then do that:

mySelection.getValues().flat().map(v=>[["/","","#N/A","#VALUE!","#VALEUR!"].includes(v)?null:v]);

where you can list in the inner array all the values you want to exclude from setting a note.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement