Skip to content
Advertisement

forEach function for multiple sheets in Google Scripts

I am attempting to run a script that will copy info from multiple different sheets to a different file. I am having issues with the forEach function. The error I am getting is:

Error
ReferenceError: sheets is not defined copy @ Code.gs:9 copyInfo @ Code.gs:4

JavaScript

Advertisement

Answer

If you create a function to use with forEach, that function needs to accept an individual item as a parameter. In this case, each “sheet” from SpreadsheetApp.getActive().getSheets() will be passed as the first parameter into your copy function – but the copy function doesn’t accept any params as is.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement