title: Add borders and change color of blank cells in a table
body: <p>I have a table of tournament results from my bass club in Google Sheets (see the TX Summary tab in <a href="https://docs.google.com/spreadsheets/d/1hPH2lKDtDqdjnghbYS3kWtXb3IGmunXao1JuWdi5SgM/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1hPH2lKDtDqdjnghbYS3kWtXb3IGmunXao1JuWdi5SgM/edit?usp=sharing</a>).  The table is the result of a QUERY function grouped by member and pivoted by event number.  When a club member doesn't participate in a particular tournament, the corresponding cell in the table is blank.</p>
  
  <p><a href="https://i.stack.imgur.com/QaThs.jpg" rel="nofollow noreferrer">Click here for an image of the desired table state</a></p>
  
  <p>I have a Google script (see below) that I copied and modified, which changes borders and colors of cells on the active sheet.  It works great if the QUERY  result has values populated in all cells.  I'm able to change blank cells outside the table to #0066cc with no borders.  I'm able to change cells containing a value within the table area to #dbdbdb with borders on all sides.</p>
  
  <p>What I'm struggling with is when the QUERY result contains BLANK cells.  For those situtations, I want to add borders and change the color to #aaaaaa.  Currently, the script is coloring blank cells within the table #0066cc and not adding borders (falling through to the else statement).  I end up with a table that looks like I've been playing BREAKOUT (remember that one?).  I've tried multiple variations of comparisons in the second if statement (I thought == "" or === "" would do it) in an attempt to alter those cells, but I just can't seem to get it to work.  I know I'm probably missing something really, really simple, but after looking at this till my eyes bleed, I can't see the forest for the trees.  Any help would be greatly appreciated.</p>
  
  <p>Thanks,</p>
  
  <p>Duke Bevard</p>
  
  <pre><code>function summaryBorders() {
  var doc = SpreadsheetApp.getActiveSheet()
  var range = SpreadsheetApp.getActiveSheet().getRange(1, 1, doc.getMaxRows(), doc.getMaxColumns());
  var cells = doc.getRange(1, 1, doc.getMaxRows(), doc.getMaxColumns()).getBackgrounds();
  range.setBorder(false, false, false, false, false, false);
  var values = range.getValues();
  for (var i = 0; i &lt; values.length; i++) {
    for (var j = 0; j &lt; values[i].length; j++) {
      if (values[i][j] !== "") {
        range.getCell(i + 1, j + 1).setBorder(true, true, true, true, true, true)
        cells[i][j] = "#dbdbdb";
        if (values[i][j] == "" &amp;&amp; j &gt;=2 &amp;&amp; j&lt;15) {
          range.getCell(i + 1,j + 1).setBorder(true, true, true, true, true, true)
          cells[i][j] = "#aaaaaa";
          }
      } else {
        cells[i][j] = "#0066cc";
      }
    }  
  }
  doc.getRange(1, 1, doc.getMaxRows(), doc.getMaxColumns()).setBackgrounds(cells);
  </code></pre>
  
  <p>}</p>