I want to create a new sheet whose sheet name is the same as the value in column D and the data in each sheet corresponds to the row of value data in column D. column D value is about title.
for example: there is new data added and I will check column D if there is different new data if there is then a new sheet will be created automatically with the same title as the new data and the data in the sheet only has rows of data related to the new data. the data comes from the google form and from the response sheet the data is taken.
the data table looks like this.
sheets response.
sheets based on value column. sample lifehack sheets
I tried to use this scripts and it works to create new sheets whose names match the values in column D but the data still cannot be filtered according to the related values only. can anyone help to make the data related to the sheet title only taken from the response sheet?
Here is the scripts code.
function onOpen() {
var menu = [{
name : "Add",
functionName : "newSheet"
}
];
SpreadsheetApp.getActiveSpreadsheet().addMenu("Create New Sheet", menu);
}
function newSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getActiveSheet();
var sheet1 = ss.getSheetByName("Sheet1")
var getNames = sheet1.getRange("D2:D").getValues().filter(String).toString().split(",");
for (var i = 0; i < getNames.length; i++) {
var copy = ss.getSheetByName(getNames[i]);
if (copy) {
Logger.log("Sheet already exists");
} else {
templateSheet.copyTo(ss).setName(getNames[i]);
ss.setActiveSheet(ss.getSheetByName(getNames[i]));
ss.moveActiveSheet(ss.getNumSheets());
}
}
}