Create a new sheet for each row in a Google Sheets spreadsheet using Apps Script

In this tutorial, I will show you how to create new sheets in a Google Sheets spreadsheet based on the data in a given sheet. Let's say that you have a sheet called CreateSheets containing the names of sheets you want created programmatically. You want to create a new sheet in your spreadsheet for each row in this sheet. I will show you how to use Apps Script to automatically create new sheets based on the data that you've entered in Google Sheets.

Below is a screenshot of the sheet containing names of sheets you want created.

The code below reads data from a sheet called CreateSheet" and inserts a new sheet for each row in this sheet.

function createNewSheetPerRow() {
  // Get the data from the sheet called CreateSheets
  var sheetNames =   SpreadsheetApp.getActive().getSheetByName("CreateSheets").getDataRange().getValues();

  // For each row in the sheet, insert a new sheet and rename it.
  sheetNames.forEach(function(row) {
    var sheetName = row[0];
    var sheet = SpreadsheetApp.getActive().insertSheet();
    sheet.setName(sheetName);
  });
}

When you run the createNewSheetPerRow() function, you'll see three new sheets created because the CreateSheets sheet had three rows in it.

Screenshot of a Google Sheets spreadsheet.

Conclusion

In this tutorial, I showed you how to create a new sheet for every row in a Google Sheet.

Thanks for reading!


Have feedback for me?

I'd appreciate any feedback you can give me regarding this post.

Was it useful? Are there any errors or was something confusing? Would you like me to write a post about a related topic? Any other feedback is also welcome. Thank you so much!