1
votes

I am trying to update certain cells in Google Spreadsheet using my own code using Google App Script.

Let say I have 2 cells (A1 and A2) filled with 1 and 2.
In the cell C1, I have used custom function called "AutoUpdateMyCell".

What the function does is just getting values from A1 and A2 and add to each other, and fills the cell (C1) with the new value (which is 3).

But the problem starts when I change 1 of the values in either A1 or A2. The value in C1 doesn't update automatically.

How can I also make C1 update when I change 1 of the values in A1 or A2?
I know there is a function onEdit(), but I am not sure how to use that for my problem.

I could just use onEdit, and get the values from A1 and A2 and then put that in C1, but I want to make it dynamic, so I don't have to check for specific cells, if you get want I mean.

This is my function in pseudo code

function AutoUpdateMyCell(cell1, cell2)
{
    var value1 = cell1.getValue();
    var value2 = cell2.getValue();

    return value1 + value2;
}
1
Why don't you use spreadsheet native functions to do that?Serge insas
I am trying to understand how Google App Script and Google Spreadsheets works. And this seems like a simple thing to do, but apparently notDijkeMark
Possible duplicate of stackoverflow.com/questions/13730163/…Tim

1 Answers

1
votes

No need to use getValue(). its value what is passed and not cell reference.

function DoConcatenate(cell1, cell2)
    {
     var String1 = cell1.toString();
     var String2 = cell2.toString();
     return String1+String2;
    }
function DoAddition(cell1, cell2)
    {
     return cell1+cell2;
    }