title: Conditional borders in Google Sheets
body: <p>I am trying to do exactly what <a href="https://stackoverflow.com/questions/49001234/add-border-format-to-row-if-condition-met-in-google-sheets">Add border format to row if condition met in Google Sheets</a> is asking, but the accepted answer simply does not work. The original post was very clear, so here it is once more:</p>
  
  <blockquote>
    <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.</p>
  </blockquote>
  
  <p>The accepted answer to this original post provides the following script:</p>
  
  <pre><code>function onOpen() {
     GroupMyData(); // trigger this function on sheet opening
  }
  
  function GroupMyData() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName('Sheet 1'); // apply to sheet name only
    var rows = sheet.getRange('a1:g'); // range to apply formatting to
    var numRows = rows.getNumRows(); // no. of rows in the range named above
    var values = rows.getValues(); // array of values in the range named above
    var testvalues = sheet.getRange('a1:a').getValues(); // array of values to be tested (1st column of the range named above)
  
    rows.setBorder(false, false, false, false, false, false, "red", SpreadsheetApp.BorderStyle.SOLID_MEDIUM); // remove existing borders before applying rule below
        //Logger.log(numRows);
  
    for (var i = 0; i &lt;= numRows - 1; i++) {
        var n = i + 1;
        //Logger.log(n);
        //Logger.log(testvalues[i] &gt; 0);
        //Logger.log(testvalues[i]);
        if (testvalues[i] &gt; 0) { // test applied to array of values
          sheet.getRange('a' + n + ':g' + n).setBorder(null, null, true, null, null, null, "red", SpreadsheetApp.BorderStyle.SOLID_MEDIUM); // format if true
        }
    }
  };
  </code></pre>
  
  <p>That script functions like so:
  A border will appear along the bottom of each row where column A's cell has a number in it (and no letters), regardless of whether the number is the same as the one in the cell above it or different.</p>
  
  <p>However the goal is for A to have text, and wherever consecutive text down column A changes from a repeated string to a differing string, there should be a border between the differing strings.</p>