user14807564
user14807564

Reputation:

Script has an error while running the code

I am new to Google Sheet App Script and trying to to create a IF condition with it but receiving an error.

I want to populate This "Right" result in Cell AO3

Your help will be appreciated

function myFunction() {

 var sheet = SpreadsheetApp.getActive().getSheetByName('DATA')
 var ss = sheet.getRange()

   if(ss.getRange("i3").getValue()!='' 
   && 
   ss.getRange("h3").getValue()!='')
   
   {

console.log("Right!");
  
}
}

enter image description here

Upvotes: 0

Views: 54

Answers (1)

Marios
Marios

Reputation: 27390

Issues:

  1. You didn't pass any parameters in the getRange() method.

  2. Even if you did the first part correctly, in your code, ss is already a range object because you already used getRange(..). Therefore you can't use getRange(..).getRange('i3') twice.

Solution:

function myFunction() {
 var ss = SpreadsheetApp.getActive().getSheetByName('DATA');
 if(ss.getRange('i3').getValue()!='' && ss.getRange("h3").getValue()!='') { 
      console.log("Right!");
     ss.getRange('ao3').setValue("Right!");
  }
}

Upvotes: 1

Related Questions