r/GoogleAppsScript • u/deftPirate • Aug 15 '25
Question First experience scripting, kind of lost
I followed a youtube tutorial (this one) to put together a script hoping to make a button that would check/uncheck certain sets of boxes on a sheet.
Differences I'm certain of:
The tutorial used a specific named sheet for const ws = ss., where I used getActiveSheet
- This is because if the button works, I'll want to create a handful more sheets with identical layouts but different values, each with the same columns of boxes to check/uncheck
The tutorial had a different setup for the range of boxes, something like "the whole column minus one".
- I tried to adapt this because I would like to be able to check/uncheck boxes across multiple columns with one button.
The test run produces this error and, to be blunt, I have no idea what it means. Is it "not a function" because of the notation I did for the multiple columns? Or is ws.getRange itself wrong somehow?
4
u/ErizoYagami Aug 15 '25
You forgot to invoke the getActiveSheet. Put () after getActiveSheet
3
u/konkonjoja Aug 15 '25
On line 3 it should be: const ws = ss.getActiveSheet(); Instead of const ws = ss.getActiveSheet;
It's a function and the empty parenthesis mean that it's called without arguments. I didn't check the test of your code, since I'm on mobile. Also try pasting your code in some LLM like chat gpt with the error message and ask for a correction and an explanation. Good luck!
5
u/mommasaidmommasaid Aug 15 '25 edited Aug 15 '25
There are range.check() and range.unCheck() methods specifically to check/uncheck checkboxes.
I'd recommend using those because they won't affect non-checkbox cells, meaning you don't have to precisely define a range as you are (attempting to) now.
In addition those functions will work if the checkboxes have custom values other than true/false.
To do all of the checkboxes on a sheet:
If you are planning a button on each sheet, consider instead creating a custom menu created from onOpen()
Check / Uncheck All
Or if you want to do it only on certain ranges on certain sheets, consider using a dropdown whose options contain a custom "signature" character, or custom checkbox with a signature "checked" value, and detect that signature character from an onEdit() trigger.
An advantage to that is it provides some context to the script, i.e. you can get the location of that dropdown from from script.
So you could for example set/clear checkboxes that in the column below the dropdown.
That can avoid hardcoding ranges in your script entirely, which greatly reduces maintenance issues down the road.
1
u/Longjumping_Eagle_68 Aug 15 '25
Recommendation: use chat gpt, grok or even gemini for app script training and learning. Better code, really deep explanations. 3x faster and 3x better than youtube.