0

I have some code that will only execute upon save (not even upon manual RUN, but only on Save). The code is a commission calculator... designed to compute assign 3 variables... X, Y, and Z that store 13%, 14%, and 15% respectively of the gross profit value stored in B13.

Right now I have it just returning X as a method to check that the v script was working. It does in fact work, but does not run OnEdit, as I have setup my triggers to do. It instead only runs when I click Save on the script editor.

Any help appreciated.

function myFunction() {

var ss = SpreadsheetApp.getActiveSpreadsheet();

var sheet = ss.getSheetByName('Sheet1');
var range = sheet.getRange("B13"); 
var data = range.getValue();

var a=(data*.13);
var b=(data*.14);
var c=(data*.15);

if(a<=150)
{(X=150);}

if(a>150)
{(X=a);}

if(b<=150)
{(Y=150);}

if(b>150)
{(Y=b);}

if(c<=150)
{(Z=150);}

if(a>150)
{(Z=c);}

return X;

}
Gary Enos
  • 1
  • 1
  • How are you triggering the code? – Karl_S Aug 10 '17 at 17:01
  • Run -- OnEdit Events-- From Spreadsheet , OnEdit Keep in mind... the script doesn't actually fulfill it's purpose even when I manually run (click the 'play' button)... only when I save. – Gary Enos Aug 10 '17 at 17:05
  • Is another function calling this? `return X;` just means the function passes X back to whatever is calling this function. If myFunction() is set to be run On Edit, then it will run but nothing will happen. Add `Browser.msgBox(X);` prior to the line with return and you should see something with each edit if this function is triggered On Edit . If a cell in your spreadsheet had `=myFunction()` then change it to be `=myFunction (B13)` and every time B13 is edited, the value in this cell will change. In this case you can remove the On Edit trigger. – Karl_S Aug 10 '17 at 17:34

0 Answers0