Answer the question
In order to leave comments, you need to log in
How to shorten this google apps script code?
Hello,
There is a table with a list of all available tables (the names of these tables may change). To keep the list of titles up-to-date, I wrote a script that takes the id of the tables from the "C" column, opens the table by this id, takes the title and inserts it into the "B" column. The problem is that the list is constantly updated and it is not convenient to change the script, so I would like to write it as a loop
function GetSpreadSheetsName33() {
var SpreadSheets = SpreadsheetApp.openById('Тут ID Таблицы').getSheetByName('Accesses');
var Data = SpreadSheets.getRange("C2").getValue();
var SheetName = SpreadsheetApp.openById(Data).getName();
SpreadSheets.getRange("B2").setValue(SheetName);
var Data = SpreadSheets.getRange("C3").getValue();
var SheetName = SpreadsheetApp.openById(Data).getName();
SpreadSheets.getRange("B3").setValue(SheetName);
var Data = SpreadSheets.getRange("C4").getValue();
var SheetName = SpreadsheetApp.openById(Data).getName();
SpreadSheets.getRange("B4").setValue(SheetName);
var Data = SpreadSheets.getRange("C5").getValue();
var SheetName = SpreadsheetApp.openById(Data).getName();
SpreadSheets.getRange("B5").setValue(SheetName);
var Data = SpreadSheets.getRange("C6").getValue();
var SheetName = SpreadsheetApp.openById(Data).getName();
SpreadSheets.getRange("B6").setValue(SheetName);
var Data = SpreadSheets.getRange("C7").getValue();
var SheetName = SpreadsheetApp.openById(Data).getName();
SpreadSheets.getRange("B7").setValue(SheetName);
}
function GetSpreadSheetsName() {
var i = 2;
var SpreadSheets = SpreadsheetApp.openById('Тут ID таблицы').getSheetByName('Accesses');
while (SpreadSheets.getRange("C"+i).getValue().lenght>1)
{
i++;
var Data = SpreadSheets.getRange("С"+i).getValue();
var SheetName = SpreadsheetApp.openById(Data).getName();
SpreadSheets.getRange("B"+i).setValue(SheetName);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question