Reputation: 1943
I have a spreadsheet in which I want to be able to expand the number of columns using a function rather than using auto-fill because the new cells are getting filled with content based on complex formulas and depending on a lot of things.
In one of these cells I want the content to be something like =SUM(A1:A8)
But if I just do cell.setValue("=SUM(A1:A8)")
I get "error: Unknown range name A1", unless I afterwards edit the cell content and press enter, without really having changed its content.
Is there any way of fixing this?
I don't want the calculation to be in the expand-columns-function because I do want the cell-calculation to be updated when one of the referenced cells change.
Is there a way of doing it besides having an onEdit
-function listening to changes in the referenced cells and updating the calculations?
Thanks
Upvotes: 2
Views: 2806
Reputation: 17752
To set a formula on a cell you should use cell.setFormula
not setValue
.
I'm not sure I understood you "expand" issue completely, but I think an opened range sum function may suit you better than apps-script. e.g.
=SUM(A:A)
or =SUM(A2:A)
Upvotes: 6