Home > Blockchain >  Checkbox in Google Sheet
Checkbox in Google Sheet

Time:10-29

Is there a way where a checkbox will automatically appear when new data is entered in google sheet? So this will save time for me that whenever new data is entered, there's a corresponding checkbox to it.

Thank you!

CodePudding user response:

You can use this script to do so:

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var sheet = ss.getActiveSheet(); 
  var range = sheet.getRange(1,1,sheet.getLastRow(),1);
  var values = range.getValues(); //gets the values on ColA

  for(var i = 1; i < values.length; i  ){
    if(values[i] != ""){ //this is the condition to check if Column A values is not blank.
      sheet.getRange(2,3,i,1).insertCheckboxes(); //inserts the checkbox on column C per iteration.
    }
  }
}

What this does is that it checks Column A if it's not blank, it will add a checkbox on Column C per value on Column A.

Before running the script:

enter image description here

After running the script:

enter image description here

For best results, you can associate this function on a trigger by going to App Script > Triggers page like so:

enter image description here

You have options for onChange, onEdit, onFormSubmit, or onOpen event driven triggers.

References:

enter image description here

  • Related