0

I have hundreds of checkboxes in multiple sheets on a single Google Sheets project.

When a user clicks a checkbox, I want a script to activate.

In that script, I need to know what cell the checkbox that was clicked is in. Is there a way to do this without making a hundred different scripts for each checkbox and hard-coding the location of each of those cells?

For example if I clicked on this checkbox

enter image description here

I would want my script to know that it was activated from Sheet12:B2. If the specific sheet is not possible, then just the cell location (B2 in this case) is sufficient.

2

Use on edit / on change triggers and the corresponding event object.

Example

function onEdit(e){
  var a1Notation = e.range.getA1Notation();
  e.source.toast(a1Notation + ' was clicked');
}

Related

References

  • Some of events may be "undocumented" and/or not available in certain cases (for example, the 'oldValue' isn't available in a copy/paste scenario). Logger.log(JSON.stringify(e)) is a handy way to see what event information is available. Chaining can get you a long way too, such as how @Rubén chained e.range to create var a1Notation = e.range.getA1Notation();. – Tedinoz Dec 6 '19 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.