Rename a sheet in Google Sheets using Apps Script

In this tutorial, I will show you how to rename a sheet in a Google Sheets spreadsheet using Apps Script. This is actually very easy to do and the Apps Script code is just a couple of lines long.

The function renameSheet() accepts two parameters: (1) the current name of the sheet and (2) its new name.

First, we get a reference to the sheet by using the getSheetByName(currentName) method of the Sheet class and then we rename it using the setName(newName) method.

function renameSheet(currentName, newName) {
 // Get a reference to the sheet using its existing name
 // and then rename it using the setName() method.
 SpreadsheetApp.getActive().getSheetByName(currentName).setName(newName);
}

To use the function, just call it with the sheet's current and new name.

renameSheet("hr", "Human Resources");

Conclusion

In this tutorial, I showed you how to rename a sheet in a Google Sheets spreadsheet using Apps Script.

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!