0
votes

I have a value in a google sheet which is "test2".

Using Google apps script I have created a custom formula TE using the formula below.

I input the formula in the adjacent cell =TE(test2), the value it outputs is incorrect. In the script below, it keeps picking up test 1 value always as -125 and the if statements are not working.

Please can anyone help?

function TE(AL) {

var RH = -110;
var HF = -30;
var AC = '';

if (AL = "test1") {
   AC = -125;
 } else if (AL = "test2") {
    AC = -135;
 } else {
    AC = -100000;
 }
 var TC = RH + HF + AC;


Logger.log (TC);

return TC;

}
1
Perhaps you could use == for AL = "test1" stackoverflow.com/questions/20404002/…The fourth bird
I have tried this too but it didn't work unfortunately thank for your commetRishiP
What is your cell formula looks like? is it =TE("test2") or =TE(test2).Srikanth
It most definitely should be == otherwise the first if sets AL to the value "test1".TheWizEd
Hi - I believe it's set to =TE(test2)RishiP

1 Answers

1
votes

Try this:

function TE(AL) {
  var RH=-110;
  var HF=-30;
  var AC='';
  if(AL=="test1")
  {
    AC=-125;
  }else if(AL=="test2")
  {
    AC=-135;
  }else{
    AC=-100000;
  }
  var TC=RH+HF+AC;
  return TC;
}

Here's what it looks like on my spreadsheet:

enter image description here