Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
setValue cannot change the latest data if its value is 'O'

I have a function that it will detect the change of google sheet when anyone write something into google sheet. However,there is a problem. It cannot change the latest data if its value is 'O'. It still can send mail,but setValue() just didn't work on the latest data.

Does anyone know how to fix this problem? Here is my sheet data.

enter image description here

function sentMail(confirm) {
  var spreadsheet = SpreadsheetApp.openById('XXXXXXXX');
  var sheet = spreadsheet.getSheetByName('QAAZ');

  var mail = "xxx@gmail.com";
  var title = "test mail"

  var lastRow = sheet.getLastRow();
  var lastCol = sheet.getLastColumn();
  var range = sheet.getRange(1,1,lastRow,lastCol);
  var values = range.getValues();

  var rowCount = 2;
  var colCount = 14;
  
  Logger.log(values [rowCount][colCount - 1]);
  Logger.log(lastRow);
  lastRow = lastRow + 1;

  for(rowCount = 1; rowCount <= lastRow + 1; rowCount++){
    if(values [rowCount][colCount - 1] == 'O'){
      if(values [rowCount + 1][colCount -1] == 'O'){
        sheet.getRange(rowCount, colCount).setValue('V');
        sheet.getRange(rowCount + 1, colCount).setValue('V');
      }
      else{
        sheet.getRange(rowCount, colCount).setValue('V');
      }
      GmailApp.sendEmail(mail, title, "test");
      Logger.log(values [rowCount][colCount - 1]);
    }
  }

  

  
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!