简体   繁体   中英

Is there a function to only change value of cells that have numbers in them in a column, or a function to avoid empty cells

I was looking for a function to check the cells in a column and if they have a number in them, it would set their value to 0 or possibly avoid blank cells

function reset() { SpreadsheetApp.getActiveSheet().getRange('I17:I118').setValue('0')
}

That's the current code I have, but that changes every single cell in the range to a 0, but I want it to only change cells that have a number in them to a 0

Try this:

function resetCellThatContainANumber() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  var rg=sh.getRange('I17:I118');
  var vA=rg.getValues();
  for(var i=0;i<vA.length;i++) {
    if(!isNaN(vA[i][0])) {
      vA[i][0]=0;
    } 
  }
  rg.setValues(vA);
}

My Example Before and After running function

在此处输入图片说明

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