title: Returning formula in google script
body: <p>In Google Spreadsheet in want to subtract one cell with another based on a value in yet another cell. </p>
  
  <p>example:</p>
  
  <pre><code>If cell A1 = "Yes" 
    subtract B1 from C1 
  
  If cell A1 = "No"
    subtract B1 from D1
  
  If cell A1 = ""
    subtract B1 from C1
  </code></pre>
  
  <p>I think a have to build a little script for this one (not sure) and have come up with this:</p>
  
  <pre><code>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
      }
  </code></pre>
  
  <p>Now it returns the proper range, but the formula is not going in effect. The script pastes the range literally in the cell.  </p>