How do I create a script to rename the second sheet in a workbook no matter what the current sheet name is?
I have a script that deletes all of the sheets except for the 1st and 2nd one.
Then I want to rename the second sheet with today's date. I have everything else except renaming.
Double-click the sheet tab, and type the new name. Right-click the sheet tab, click Rename, and type the new name.
1. Ctrl + Click each sheet tab at the bottom of your worksheet (selected sheets will turn white). 2. While selected, any formatting changes you make will happen in all of the selected sheets.
Touch a worksheet tab at the bottom of your screen to select the sheet so that you can get started changing it. On Android tablets and phones, a dialog box will ask you to enter the new sheet name. Press OK to confirm changes. On iOS devices, a cursor will appear letting you change the name directly on the tab.
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var tz = ss.getSpreadsheetTimeZone();
var sheets = ss.getSheets();
var date = Utilities.formatDate(new Date(), tz, 'MM-dd-yyyy');
sheets[1].setName(date); // Rename second
}
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With