Search code examples
google-apps-scriptgoogle-sheets-api

Use Checkbox to auto input


I am using google spreadsheet for a project. While making, I have faced a difficulty of not knowing how to code the following behavior:

When a checkbox is checked, input the data on the specific row automatically.

To give an example, if I check the checkbox on cell A20 I want data in B20, C20, D20 to auto input into cell C9, C11 and C13.

I believe this is a simple code but I am not quite familiar with this language... Any help?


Solution

  • Try this:

    function onEdit(e) {
      const sh = e.range.getSheet();
      if (sh.getName() == "Sheet1" && e.range.columnStart == 1 && e.range.rowStart > 19 && e.value == "TRUE") {
        ["C9", "C11", "C13"].forEach((r, i) => sh.getRange(r).setValue(e.range.offset(0,i + 1).getValue()));
      } 
    }