You have an interesting problem on your hands, and I think its solution is easier than it seems. I have written a small script that you can use as a guide, I believe that without having experience you will be able to complete it.
const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1')
const setDynamicFormulas = () => {
/* Create the dinamic formulas */
const formula1 = (n) => `=IFS(B${n}<=10,40,B${n}>10,50)`
const formula2 = (n1, n2) => `=SUM(E${n1}:E${n2})`
/* We loop over the sheet making 10 cell jumps */
for (let i = 0; i < 100; i = i + 10) {
/* Assing the values for our formulas */
const f1 = formula1(7 + i)
const f2 = formula2(5 + i, 14 + i)
/* Set the values for the formulas */
ss.getRange(6+i, 2).setFormula(f1)
ss.getRange(7+i, 2).setFormula(f2)
}
}
What I do in the script is to create a dynamic formula for each of the formulas you want to iterate. For example for the formula that is in B6
:=IFS(B7<=10,40,B7>10,50)
, we realize that the dynamic part, is the one that refers to B7
in the following iterations will be: B17
, B27
, etc... So, we already know that the number increases in ten units each iteration. How can we write a dynamic formula with this information? Very easy, we simply indicate between ${}
our dynamic part. It would look like this:
const formula1 = (n) => `=IFS(B${n}<=10,40,B${n}>10,50)`
// formula1(17) will be =IFS(B17<=10,40,B17>10,50)
Okey, but what happens with the next formula? =SUM(E5:E14)
we have two dynamic parts, right? No problem, we indicate two dynamic parts:
const formula2 = (n1, n2) => `=SUM(E${n1}:E${n2})`
// formula2(15, 24) wil be =SUM(E15:E24)
What's next? As we have said, we need to make jumps of 10 units, so we need a for
loop that makes those jumps, create the formula dynamically and assign it to each of the cells.
for (let i = 0; i < 100; i = i + 10) {
// The cell starts at 7, so we need to add it
const f1 = formula1(7 + i)
// Assign the value to the cell
ss.getRange(6+i, 2).setFormula(f1)
}
Congratulations! you already have your formulas in the place you need and dynamically modified. You only need to fill it with each of the remaining formulas.
Documentation