Trigger which includes a fixed cell reference is not firing

Viewed 29

I am trying to set an email trigger whenever the cell Value of Column E > Cell Value G1.

G1 is dynamic, so I cannot just put in a fix value therefore. I created the variable q3 for the value of G1 and I created the variable vA for array values of column E.

This is the code but somehow my script does not fire as it does not understand the q3 value in the loop. I wonder if its a syntax issue. Any help is appreciated.

function readCell() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('test'); 
  var q3=SpreadsheetApp.getActiveSheet().getRange('G1')
  var vA=rg.getValues();


      if(Number(vA[i][5])>q3) {
        MailApp.sendEmail('blabla.sd@gmail.com','Hello World!')
      }
    }
1 Answers

In q3 variable you are only storing the range[reference to G1] and not the actual value of G1.

You can try something like this.

function readCell() {
  var spreadsheet=SpreadsheetApp.getActive();
  var sheet=spreadsheet.getSheetByName('test'); 
  var G1_value=sheet.getRange('G1').getValue();
  var E_values=sheet.getRange('E1:E').getValues();

  for (var i=0; i<E_values.length; i++) {
     if (Number(E_values[i][0]) > Number(G1_value)) {
        MailApp.sendEmail('to@gmail.com', 'Subject', 'Body');
     }
  }
}
Related