javascript - Returning formula in google script -


in google spreadsheet in want subtract 1 cell based on value in yet cell.

example:

if cell a1 = "yes"    subtract b1 c1   if cell a1 = "no"   subtract b1 d1  if cell a1 = ""   subtract b1 c1 

i think have build little script 1 (not sure) , have come this:

function sub() {    var ss = spreadsheetapp.getactivespreadsheet();   var sh = ss.getactivesheet();    var nrange = ss.getrangebyname("sub");   var group = nrange.getvalues();;    var range;      if ( group == "yes" ) {      range = '=q15-n15' }     else if ( group == "no" ) {      range = "=q15-m15"}     else if ( group == "" ) {      range = "=q15-m15"}      return range     } 

now returns proper range, formula not going in effect. script pastes range literally in cell.

if use .getvalues() read content of range, receive two-dimensional array of values - if there 1 cell in range. if want 1 value, use .getvalue() instead.

because you're getting array, 3 of if tests evaluate false, , none set value range. try giving range default value start:

var range = 'range not set'; 

note: custom functions return values, cannot set cell's formula. function return result of calculation, or line of text display in cell. if must set formula, you'll have using function that's invoked other way, , use range.setformula().


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -