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.