0

I'm trying to find a specifc conditional format for a scenario on google sheet but I was unable to find anything regarding this (than changing color, format text etc).

Is it possible to write an onEdit(e) script that conditions if column Hn==Yes then make column I(checkbox) available to be pressed?

I tried with setFrozenColumns(9) is H column is blank or No but it doesn't work.

function chechBox(e) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = e.range.getSheet();
  var range = e.range;
  if(sh.getName()!="Test")return;
  var colHValue=sh.getRange(e.range.rowStart,8).getValue()
  if (range.getColumn()==8 & colHValue==0 & colHValue=="No"){
    sh.setFrozenColumns(9);
  }
};

Thank you, M

Cooper
  • 59,616
  • 6
  • 23
  • 54
MrrrDude
  • 21
  • 1
  • 7

1 Answers1

1

Try it this way:

function chechBox(e) {
  var sh = e.range.getSheet();
  if(sh.getName()!="Test")return;
  var colHValue=sh.getRange(e.range.rowStart,8).getValue();
  if (e.range.columnStart==8 && (colHValue==0 || colHValue=="No" )){
    sh.setFrozenColumns(9);
  }
}

I'm not sure where you wanted to do this:

if(sh.getRange('H2').getValue()=="Yes")sh.getRange('I2').insertCheckboxes();
Cooper
  • 59,616
  • 6
  • 23
  • 54
  • I tried this way, but didn't work as I already had the Checkboxes inserted but I found a workaround, I added another condition in my *insertRow" function if colHValue=="Yes" & range.getColumn()==9 & colIValue==true then insert row otherwise do nothing. Thank you for your answear @Cooper really quick to give help and you really gave me this idea. – MrrrDude Dec 14 '19 at 07:44
  • If you can use the information that's already in the event object you can save the time of running another function. You can use Logger.log(e) to get the event object and view it with view logs. – Cooper Dec 14 '19 at 15:48