简体   繁体   中英

How would I go about adding a checkbox to Google Sheets based on whether there is a value within either of 2 columns to the left?

I'm trying to make a spreadsheet for something and I've run into a problem in how I want a column to work.

I want the Column F to create/delete a checkbox if there is/isn't a value within the D or E columns

I'm a javascript noob, I've basically only created a minor menu mod for minecraft. Is anyone able to help me by telling me how to reference certain cells and whether it contains anything within my sheet to input a checkbox/clear the value?

Or help write the function if you're bored haha

I've included an example image below.

example table

You will need to add your sheet name and possible a condition on e.range.rowStart if you have header rows

function onEdit(e) {
  //e.source.toast('Entry');
  const sh=e.range.getSheet();
  if(sh.getName()=="Sheet1" && e.range.columnStart>3 && e.range.columnStart<6 && e.value) {
    sh.getRange(e.range.rowStart,6).insertCheckboxes()
  }
}

Note: you cannot test this function from the script editor as it requires an event object from the onedit trigger. No trigger?No workie.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM