A
A
arr0w2021-04-27 16:09:41
Google Apps Script
arr0w, 2021-04-27 16:09:41

String automation?

You need to write a formula:
spreadsheet.getRange('C 2 ').activate();
spreadsheet.getCurrentCell().setFormula('=IMPORTRANGE(" https://docs.google.com/spreadsheets/d/ "; "Indicator!C 2 ")');
1240 times. Increasing the selected values ​​by 1.
That is, in each subsequent cell, a formula should be obtained that differs in the cell number by 1.

Example:

spreadsheet.getRange('C2').activate();
spreadsheet.getCurrentCell().setFormula('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/"; "Показатель!C2")');
spreadsheet.getRange('C3').activate();
spreadsheet.getCurrentCell().setFormula('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/"; "Показатель!C3")');
spreadsheet.getRange('C4').activate();
spreadsheet.getCurrentCell().setFormula('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/"; "Показатель!C4")');


Please help write the script.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2021-04-27
@arr0w

Hard, metallic (c)
You can do it like this:

=IMPORTRANGE("https://docs.google.com/spreadsheets/d/"; "Показатель!C2:C")

And if you still want 1000+ formulas, then something like this:
const formulaTemplate = '=IMPORTRANGE("https://docs.google.com/spreadsheets/d/"; "Показатель!C2")';
let range = spreadsheet.getRange('C2:C1240');
let formulas = range.getFormulas();
formulas = formulas.map((row,ri)=>row.map(f=>formulaTemplate.replace('!C2', '!C'+(ri+2))));
range.setFormulas(formulas);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question