Search code examples
google-sheetsgoogle-apps-script

How can I automatically set the current date and time when the checkbox is activated?


I need help, I want every time the check box is active that I have all of them in column G to put the current date and time in column F in its corresponding row.

I have tried to look for code that does it but what I found was that the box is automatically set when I type anything in the box and I only want it to be activated with the check box3

Screenshot

Let the box in column F be set to the current date and time, just click the check box in column G.


Solution

  • Try this:

    function onEdit(e) {
      const sh = e.range.getSheet();
      if(sh.getName() == "Your sheet name" && e.range.columnStart == 7 && e.value == "TRUE") {
        e.range.offset(0,-2).setValue(new Date());
      }
    }