0

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

4
  • 1
    Welcome to Web Applications. Please follow the tour, read How to Ask and add a brief description of your search/research efforts. Also it could be a good idea to describe what does the code included and if there is a problem with it.
    – Rubén
    Jun 2 '20 at 22:00
  • 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" Jun 3 '20 at 4:05
  • 1
    What is the problem with the code? Does it throws an error? How are you running it?
    – Rubén
    Jun 3 '20 at 4:24
  • @Rubén : 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" Jun 3 '20 at 4:27
0

Choose one of the following options

  1. instead of getValue() use getDisplayValue() the first return a boolean for a Google Sheets TRUE/FALSE values while the second returns a string

  2. instead of "TRUE" use true
    true is the JavaScript equivalent for Google Sheets TRUE

1
  • Thank you so much. Also, I have a question. if I wanted to check a cell for a date, how would i do that? Like for example if isdate(C1) = true then do this. Jun 3 '20 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.