title: Google Sheets custom function conditional formatting
body: <p>I need to make a cell text turn red if the value of the cell is equal to the value of the cell two rows above it. I have these two functions in my script editor:</p>
  
  <pre class="lang-js prettyprint-override"><code>/**
   * Compares cell value to another cell relative in position to it.
   * Returns true if equal values.
   *
   * @param {Number} colDiff Relative positioning column difference.
   * @param {Number} rowDiff Relative positioning row difference.
   */
  function equalsRelativeCellValue(rowDiff, colDiff) {
    var thisCell = SpreadsheetApp.getActiveRange();
    var relativeCellValue = getRelativeCellValue(rowDiff, colDiff);
    if (thisCell.getValue() === relativeCellValue)
      return true;
    else
      return false;
  }
  
  
  /**
   * Returns value of cell according to relative position
   *
   * @param {Number} colDiff Relative positioning column difference.
   * @param {Number} rowDiff Relative positioning row difference.
   */
  function getRelativeCellValue(rowDiff, colDiff) {
    var range = SpreadsheetApp.getActiveRange();
    var col = range.getColumn();
    var row = range.getRow();
    var range2 = SpreadsheetApp.getActiveSheet().getRange(row + rowDiff,col + colDiff);
    return range2.getValue();
  }
  </code></pre>
  
  <p>The second function, <code>getRelativeCellValue(rowDiff, colDiff)</code> works just fine, I put <code>8</code> in a cell, and two cells below it I entered <code>getRelativeCellValue(-2, 0)</code>, and the cell evaluated to <code>8</code>.</p>
  
  <p>But the first function, <code>getRelativeCellValue(rowDiff, colDiff)</code> won't work as my custom function in conditional formatting for some reason:</p>
  
  <pre><code>Custom formula is: =equalsRelativeCellValue(-2,0)
  </code></pre>
  
  <p>The difficult part is referring to the value of the cell being referenced in the conditional formatting. But my function looks right to me, it returns <code>true</code> if the cell values are equal, and <code>false</code> if they are not. Im hoping I'm just using the "Custom formula is" feature of Conditional Formatting improperly, but the <a href="https://support.google.com/docs/answer/78413?hl=en" rel="nofollow">documentation is pretty sparse</a>.</p>