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!

Sign up to be notified when I publish new content

By signing up you agree to the Privacy Policy & Terms.