Desired to have the following Google Spreadsheet function, which (1) renames a spreadsheet (target file) and (2) populates one of its sheets based on the values contained in another spreadsheet (source file), loop through from the second row onwards until all spreadsheets listed have been renamed and populated.
All the values required for renaming the target files are in cell range D2:D.
All the values required for populating the target files are in cell range A2:D
All the IDs of the target files are in cell range G2:G.
There are no blank rows between and including the second row and the last data-containing row, and all rows with data in this range are to be used. Each of the columns (A, B, C, D, G) has the same number of data-containing rows.
The value of the number of rows which contain entries to be used is in cell range E1, if that's of any use (not used in this function).
function rnmCpyRngTo() {
//rename target spreadsheet and populate range
//in target sheet from values in source spreadsheet
//get source sheet in source spreadsheet
var ssss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CopyToWrdLists");
//get source cell range containing value of name to be given to target spreadsheet
var scrvn = ssss.getRange("D2").getValue();
//get source cell range containing values to copy to target sheet cell range
var scrvr = ssss.getRange("A2:D2").getValues();
//get source cell range containing values of target spreadsheet ID
var scrvid = ssss.getRange("G2").getValue();
//get target spreadsheet ID
var tssid = DriveApp.getFileById(scrvid);
//get target sheet
var tss = SpreadsheetApp.openById(scrvid).getSheetByName("Wordlist");
//rename target spreadsheet
tssid.setName(scrvn);
//copy values to target sheet cell range
tss.getRange(1, 1, scrvr.length, scrvr[0].length).setValues(scrvr);
}
Question 15616530 seemed close to the desired outcome but was unable to modify it to suit. Help would be much appreciated.
Added:
//get source cell range containing values of target spreadsheet ID
var scrvid = ssss.getRange("G2").getValues();
Source sheet has been shared here so that anyone with link can edit.
Assuming your signed into Google, this folder has been shared.
- The folder "Target_Spreadsheet" should have nothing in it.
- Run script "Create wordlists - TOMS" from user menus "Wordlists" to create the documents, and
- Run function "Rename and populate - TOMS" from the user menus to rename and populate the first listed file only.
Repeat as necessary. That's what I'm up to.
Thanks.