Consider I have a mastersheet with names in column A and a link in colum B, starting in row 2.
The code below, for a reason I don't understand, creates only one new sheet with the name in row 2, and sets the value of the row 3 in the newly created sheet.
I'd like that to work as followed :
- create a sheet with the name in col A
- set values of col A and col B in the newly created sheet
Can someone help me figure out what's going on ? I read the documentation about loops and getRange but I can't figure it out..
Thank you very much
function createNewSheets() {
var dataSheet = SpreadsheetApp.getActiveSpreadsheet();
var values = dataSheet.getSheetByName('mastersheet').getRange('A2:B').getValues();
// Get sheet with current swimmer name:
var sheet = dataSheet.getSheetByName(swimmerName);
var col = values[i]; // Current row
var swimmerName = col[0]; // swimmer name
// Iterate through all rows of data from "mastersheet":
for (var i = 1; i < values.length; i++) {
// Check if sheet with current swimmer name exists. If it doesn't it creates it:
if (!sheet) {
sheet = dataSheet.insertSheet(swimmerName);
}
// Sets current row of data to the new sheet:
sheet.getRange(1, 1, col.length, col[0].length).setValues(col)
}
}