I want to input a variable in a cell only if the cell is empty. The if statement, however, does not work. Any advice?
var ss=SpreadsheetApp.getActiveSpreadsh
If you already have cell value then use === or !== operators if you want avoid type conversion (where 0 == "" ).
Code snippet for decreasing not empty cell values
var sheet = ss.getSheets()[0];
var range = sheet.getRange("E2:H5");
var currentValues = range.getValues();
var newValues = [];
for (var row in currentValues) {
var newRow = [];
for (var col in currentValues[row]) {
if (currentValues[row][col] !== "") { // if not empty cell
newRow[col] = currentValues[row][col] - 1;
}
else {
newRow[col] = currentValues[row][col];
}
}
newValues[row] = newRow;
}
range.setValues(newValues);