'Connecting Functions to any sheet
I have little to no experience working with Apps Script and am trying to teach myself how this stuff works.
I have run into an issue while making a function with my current sheets. So I will give a short description of the situation to give context to my question.
I work with a production facility and we make a new sheet every day for production with the date for the day. I am trying to make a function that will automatically add numbers in a specific cell of sheets when pressed. I have made the function work, however it is attached to an old day.
My question is. Is there a way to unlock the function from a specific sheet and make it work on any sheet that we use without changing the container/sheet the function is attached to?
Edits - @Cooper - I am aware that Functions are duplicated in the sheet, such as a cell with =SUM(C12:C13), however this question is directed to Apps Script code not a regular function, those are working as intended.
@taylor.2317 the issue itself is not with the code. The script itself works as intended. My question is directly related to its application. It appears that scripts can only be run on one sheet at a time, at least by name, and in doing this I would have to either 1, have the sheet named the same every day, or 2, change the sheet the script is attached to daily. This is replica table with any script in Apps Script from my understanding.
Solution 1:[1]
I have 2 suggestions as workarounds since I don't think it can be done directly:
1. Create a custom menu in the Google Sheet. And the variable of which sheet will be workone points to the active sheet only.
var worksheet = SpreadsheetApp.getActiveSheet();
2. Rename the sheet that needs to be work everyday, and call the sheet by name in the variable. For example:
Name the worksheets dates like "01/01," "01/02," and the one for today as "Today." The next day change the names to "01/01," "01/02," "01/03" and the new one will be name "Today."
In the code the variable to get the sheet will be by name "Today"
var worksheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Today");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Giselle Valladares |
