Based on our conversation on comments, I comprehend that you want to copy all data from the Parent sheet into the specified sheets. I'll assume that the list of sheets is located in the upper left corner of the Parent sheet. If that isn't the case, please forgive me and indicate to me where the sheet list is located. This is the code that fulfills your request:
function sheetPopulator(spreadsheetID) {
var masterSheet = SpreadsheetApp.openById(spreadsheetID).getSheetByName(
"Parent");
var specifiedSheets = masterSheet.getRange(2, 1, masterSheet.getLastRow(), 1)
.getValues();
var lastRowMasterSheet = masterSheet.getLastRow();
var lastColumnMasterSheet = masterSheet.getLastColumn();
var allData = masterSheet.getRange(1, 1, masterSheet.getLastRow(), masterSheet
.getLastColumn()).getValues();
for (var i = 0; i < specifiedSheets.length; i++) {
if (SpreadsheetApp.openById(spreadsheetID).getSheetByName(specifiedSheets[
i]) != null) {
SpreadsheetApp.openById(spreadsheetID).getSheetByName(specifiedSheets[i])
.getRange(1, 1, lastRowMasterSheet, lastColumnMasterSheet).setValues(
allData);
}
}
}
That function will first gather the list of specified sheets and after that will read all the data from the Parent sheet. After that, the code will iterate over every element of the list and, if that element coincides with a sheet name, it will copy all the previously read data into that sheet.
Please, take this as one of many possible solutions to your issue. Don't hesitate to ask me for clarifications or further help.
UPDATE
I apologize if the previous script doesn't fulfill your requests. After reading your new comments I studied your spreadsheets and designed a new code. I have tested this new script on copies of your spreadsheets and it works flawlessly. This is the code in question:
function sheetPopulatorII() {
var parentSheetID = "{PARENT SHEET ID}";
var childrenListSheet = SpreadsheetApp.openById(parentSheetID).getSheetByName(
"Childs");
var childrenList = childrenListSheet.getRange(2, 1, childrenListSheet
.getLastRow() - 1, 1).getValues();
for (var i = 0; i < childrenList.length; i++) {
childrenList[i][0] = childrenList[i][0].toString().substring(39, 83);
}
for (var i = 0; i < childrenList.length; i++) {
var children = SpreadsheetApp.openById(childrenList[i][0]);
children.getSheets()[0].setName("OLD SHEET");
SpreadsheetApp.openById(parentSheetID).getSheetByName("Master").copyTo(
children).setName("Data");
children.deleteSheet(children.getSheetByName("OLD SHEET"));
}
}
I am going to explain this code step by step. First, it opens the children list sheet (inside the Parent Sheet) using .openById()
for opening the Parent spreadsheet, .getSheetByName()
to open the involved sheet, .getRange()
for selecting the list, .getLastRow()
to know how long the list is (so you can add new URLs on the future using the same code) and .getValues()
to gather the data.
Afterwards the code will iterate the list to convert the URLs into IDs with .substring()
to cut away the non-ID parts. Next, it will iterate the list again but this time it will rename the old sheet with a temporal name using .setName()
, copy the Parent sheet with .copyTo()
and delete the renamed sheet with .deleteSheet()
. This approach copy both: values and formulas. Please, contact me again if you need further help developing the code or understanding it.