The first thing that comes to my mind is to store coordinates of formulas and their range. For example http://jsfiddle.net/1xt6zw04/1/
Let’s add an array to hold changes,
var arr = []
Setting up the variables
Formulas are on those cells
var formulaField = [
{row: 2, col: 4},
{row: 2, col: 5},
{row: 4, col: 1},
{row: 4, col: 3}
]
And the ranges of the formulas are
var formulaRanges = [
{row: 0, col: 1, formulasAttached: [formulaField[1]]},
{row: 1, col: 0, formulasAttached: [formulaField[2], formulaField[3]]},
{row: 1, col: 1, formulasAttached: [formulaField[3]]},
{row: 2, col: 0, formulasAttached: [formulaField[2]]},
{row: 3, col: 0, formulasAttached: [formulaField[0], formulaField[2]]},
{row: 4, col: 0, formulasAttached: [formulaField[1]]
]
Adding changes with formulas to the arr variable
So, when you get a message from afterChange
that cell 1,1
has been changed, you look for the row: 1, col: 1
in the formulaRanges
array and push corresponding changes from formulasAttached
array. In this case only one formula holds this coordinates.
so you can add it to the arr
array.
arr.push({row: formulaRanges[2].row, col: formulaRanges[2].col})