I am trying to create a function in Google Apps Script for a Google Sheet containing data that will automatically be updated every month. I want a cell in column A with value '1/30/3800' to be deleted (i.e. I want to set its value to ''.) I cannot for the life of me figure out how to specify the cell based on its string value, NOT based on its position in the spreadsheet. I've tried these two methods:
1)
function forecastUpdate() {
let spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
let sheet = spreadsheet.getSheets()[1]
let data = sheet.getDataRange().getValues()
for (let i = 0; i <- data.length; i++) {
if (data[i] === '1/30/3800') {
data[i] = '';
}
}
}
function forecastUpdate() {
let spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
let sheet = spreadsheet.getSheets()[1]
let data = sheet.getDataRange().getValues()
for (let value of data) {
if (value === '1/30/3800') {
value = '';
}
}
}
It says it executes, but it doesn't - nothing updates in my sheet. Any tips?! Note 1: The cell that I am trying to clear has a value derived from a QUERY formula in the Google Sheet. Not sure if that matters. Note 2: I cannot select it by its position (A41) in the sheet because its position will change every month.