Hi Nigel,
If you use the following:
Var ss = SpreadsheetApp.getActiveSpreadsheet();
Var sheets = ss.getSheets();
This will return to you all the sheets in the spreadsheet as an array. So you can use that in the loop you mention to go through one sheet at a time. So sheets[0] would be the first, then sheets[1] second, and so on.
This would be better than using sheetname as a variable.
Hope this helps.
--
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/0849487f-3d8a-4fc8-8629-d4aca4b5a0c9n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/006701d84541%24ace37c10%2406aa7430%24%40gmail.com.
On Mar 31, 2022, at 4:24 PM, Nigel Hunt <nigelha...@gmail.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAHy69YpUiyo-8kmr2fGxMvW6%3D8hMEmOUHuLWmjvf3mk%3DPwxiYA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/67E8C432-7CC2-4159-84D5-112D06F10385%40bbchs.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAHy69YoccVjZG_nOAvtUkq9j_-WW_2F5LDc0T2%3DA-1qe3mKKng%40mail.gmail.com.
You can derive the sheetnames from the sheets objects themselves. This would be a better practice then hardcoding the software with the sheetnames.
Here is an example:
function myFunction() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var sheetName;
for (var i =0;i<sheets.length;i++)
{
sheetName = sheets[i].getSheetName();
// here do what you want with that sheet
// next loop will get sheetname of next sheet in spreadsheet.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAHy69YpUiyo-8kmr2fGxMvW6%3D8hMEmOUHuLWmjvf3mk%3DPwxiYA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/006501d8457a%243b7946c0%24b26bd440%24%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAHy69Yoyp7sq2EV%3DzO2zsGbVepo_K9_65X38vviOBdNv3%2B0v%3Dg%40mail.gmail.com.