I have been trying to write this code to validate a range of cells. If the cells contain the text "true" then set value as "Incorrect Data" else "DD Data"
/** @OnlyCurrentDoc */
function myFunction() {
var app = SpreadsheetApp
var activeSheet = app.getActiveSpreadsheet().getActiveSheet();
for (var i = 1; i<10; i++) {
var workingcell = activeSheet.getRange(i,1).getValue();
if( workingcell == "TRUE" ) {
activeSheet.getRange(i,2).setValue("Incorrect Data");
}
else {activeSheet.getRange(i,2).setValue("DD Data");}
}
}
The code is executing without compilation error but it is not able to recognize the cell values because it is mark "DD Data" for all the cells which is incorrect. If the cell value is "TRUE" then — "Incorrect Data" else "DD Data
Best Answer
Choose one of the following options
instead of
getValue()
usegetDisplayValue()
the first return a boolean for a Google SheetsTRUE
/FALSE
values while the second returns a stringinstead of
"TRUE"
usetrue
true
is the JavaScript equivalent for Google SheetsTRUE