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.

Screenshot of a Google Sheets spreadsheet.

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!

Master Google Sheets Automation

Sign up to receive exclusive Automation tips and tutorials!
I'll send you actionable tips on automating tasks with Google Sheets and coding with Apps Script. You'll also be notified whenever new content is published.
PLUS: Get instant access to my Birthday Reminder Template! 🎂
By signing up you agree to the Privacy Policy & Terms.

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!