I have developed a data input sheet for gathering information. I also have a script that transfers the data to a collection sheet and another that resets the input sheet by removing all entries. This method works well; however, it would be more efficient if specific cells were set to zero instead of being cleared completely while others are left blank.
Currently, I have the following script that successfully clears the required fields:
function clearData() {
var inputSheet = SpreadsheetApp.getActive().getSheetByName('Data Input');
var cellsToClear = ["C12", "C13", "C15", "C16", "C17", "C23", "C24", "C25", "C26", "C27", "C28", "C29", "C30", "H15", "H16", "H27", "H28", "H29", "H30", "C35", "C36", "C37", "H35", "H36", "H37", "C40", "C41", "H40", "H41", "C44", "H44", "H45"];
for (var j = 0; j < cellsToClear.length; j++) {
inputSheet.getRange(cellsToClear[j]).clearContent();
}
}
I attempted to incorporate the following code to set certain cells to zero, but it didn’t function as expected. Only a few cells received a zero value, while the intended cells were not affected:
var inputSheet = SpreadsheetApp.getActive().getSheetByName('Data Input');
var cellsToZero = ["C23", "C24", "C25", "C26", "C27", "C28", "C29", "C30"];
for (var j = 0; j < cellsToZero.length; j++) {
inputSheet.getRange(cellsToClear[j]).setValue(0);
}
I’d greatly appreciate any assistance with this issue!