Reputation: 1
So I have two sheets, "Program" which the first cell in each row starting at row 4 has the name of each new sheet that I want to make. I have been trying to duplicate my "Template" sheet and then referring back to the "Program" sheet to find the first cell of each row to give the "Copy of Template" its new name. This is what I have so far but I'm not getting any bugs nor does it do anything... :(
function duplicate() {
var ss = SpreadsheetApp.getActive();
ss.setActiveSheet(ss.getSheetByName('Program'), true);
function readRows() {
var sheet = SpreadsheetApp.getSheetByName('Program');
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValue();
for (var i = 4; i <= numRows - 1; i++) {
var row = values[i];
Logger.log(row);
ss.setActiveSheet(ss.getSheetByName('Template'), true);
ss.duplicateActiveSheet();
ss.setActiveSheet(ss.getSheetByName('Copy of Template'), true).setName('row');
}
};
};
Upvotes: 0
Views: 103
Reputation: 64120
Try this:
function duplicate() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Program');
var tsh=ss.getSheetByName('Template');
var sr=4;
var vA=sh.getRange(sr,1,sh.getLastRow()-sr+1,1).getValues();
for (var i=0;i<vA.length;i++) {
ss.insertSheet(vA[i][0], {template:tsh});
}
}
Upvotes: 1