title: Add border format to row if condition met in Google Sheets
body: <p>Excel apparently has this type of conditional formatting <a href="https://sites.google.com/site/techyhelp85/excel-tips/group-borders" rel="nofollow noreferrer">built-in</a>.</p>
  
  <p>I'd like to accomplish the same in Google Sheets via <a href="https://developers.google.com/apps-script/reference/spreadsheet/range" rel="nofollow noreferrer">Google Apps Script</a>. The following should demonstrate the before and after conditions:</p>
  
  <p><strong>Example Dataset</strong></p>
  
  <pre><code>        A           B           C
    1   apple     Macintosh
    2   apple     Granny Smith
    3   orange    Florida
    4   orange    Valencia
    5   pear      Garden
    6   banana    Chiquita
  </code></pre>
  
  <p><strong>Resulting Example Dataset</strong></p>
  
  <pre><code>        A           B           C
    1   apple     Macintosh
    2   apple     Granny Smith
    ---------------------------
    3   orange    Florida
    4   orange    Valencia
    ---------------------------
    5   pear      Garden
    ---------------------------
    6   banana    Chiquita
    ---------------------------
  </code></pre>
  
  <p>The script/answer to this question should display a bottom border under the entire row (of columns 'A', 'B' &amp; 'C') for rows: 2, 4, 5, &amp; 6. The spreadsheet logic is fairly straightforward: </p>
  
  <ol>
  <li>In cell <code>C1</code>, <code>=IF(A1=A2,"NOBORDER","BORDER")</code>  </li>
  <li>Then wrap the above in <code>=IF(C1="BORDER", addBorder(A1:C1), "NOBORDER")</code></li>
  </ol>
  
  <p>In a larger dataset, this formating will help the end user see logical groupings more easily. A Google Apps Script is required because the data will be updating dynamically.</p>
  
  <p>Below is some sample Google Apps Script code, but it's not working</p>
  
  <pre><code>function onEdit(event) {
    var sheet = SpreadsheetApp.getActiveSheet();
    var range = event.range;
  
    var startingRow = range.getRow();
    var numRows = range.getNumRows();
    for (var i = 1; i &lt;= numRows; i++) {
      var rowNbr = startingRow + i - 1;
      Logger.log("changed row %s",rowNbr );
      //Now check the WHOLE row
      var colLeft=1; //1=A
      var colRight=11; //11=K
      var row = sheet.getRange(rowNbr,colLeft, 1, colRight - colLeft + 1);
      if(row.isBlank()) {
        row.setBorder(false, null, true, null, null, null, "red", SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
      } else {
        row.setBorder(false, null, null, null, null, null, "black", SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
      }
    }
  }
  </code></pre>