Rename multiple sheet tabs

785 views
Skip to first unread message

fernando....@dish.com

unread,
Oct 27, 2022, 4:24:31 PM10/27/22
to Google Apps Script Community
Good day,

I would like to write function that cycles through each tab of a spreadsheet to rename the tab. The tab names are in an array (8 in total), with an equal number of available tabs (all with default naming i.e. Sheet1, Sheet2, etc.

I know a loop will be needed, but little else beyond, so I'm struggling with the syntax. Any pointers or nudges in the right direction are welcome!

cbmserv...@gmail.com

unread,
Oct 27, 2022, 6:54:15 PM10/27/22
to google-apps-sc...@googlegroups.com

Hi Fernando,

 

Not sure where you will be getting the new names to be set for the tabs. But here is a simple little function you can use to build on:

 

function cycleThroughTabs()

{

  var ss = SpreadsheetApp.getActiveSpreadsheet();

 

  var sheets = ss.getSheets();

  for (var i=0;i<sheets.length;i++)

  {

    sheet = sheets[i];

    var sheetname = sheet.getName();  // in case you need old name

    sheet.setName("NewName");  // Put source of the names here.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/21694c6a-82fa-42d6-8291-a18ad226017dn%40googlegroups.com.

Fernando DosSantos

unread,
Oct 27, 2022, 8:11:51 PM10/27/22
to google-apps-sc...@googlegroups.com
This completed the task exactly. I was adding in a second (nested) for loop, as I believed that I needed to cycle through the array separately. Your way I used the one iterator [i] to cycle through each sheet tab and each name in the array.

Thanks for your help!

---

Fernando dos Santos

Business Operations Specialist III | Direct Sales Resource Team

O:  (973) 436 – 4800

Ext: 24839

fernando....@dish.com



On Thu, Oct 27, 2022 at 6:54 PM <cbmserv...@gmail.com> wrote:

 This message originated outside of DISH and was sent by: google-apps-sc...@googlegroups.com



--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/UMZx3-8edQQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/006f01d8ea57%2405772ba0%24106582e0%24%40gmail.com.

cbmserv...@gmail.com

unread,
Oct 27, 2022, 11:33:19 PM10/27/22
to google-apps-sc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages