title: Setting zeros (0)
body: <p>We are trying to add "0" to empty cells in a Google Spreadsheets. 
  What we have come up with so far is the following code, but it set's 0 to <strong>all</strong> cells in the sheet. We would like it to only set on cell <strong>B:Q</strong>. </p>
  
  <p><a href="https://i.stack.imgur.com/YxkSR.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YxkSR.gif" alt="enter image description here"></a></p>
  
  <p>We tried to change the following, but with the same results:</p>
  
  <pre><code>   range = source.getRange("B1:Q1", lastRow, lastColumn);
  </code></pre>
  
  <p>And the complete code-snipet we use looks like this:</p>
  
  <pre><code>function zeroDatarange() {
    var range = SpreadsheetApp.getActiveSheet().getDataRange();
    zero(range, null);
  }
  
  
  function zero(source, type) {
    var data, range;
    if(type === 'sheet') {
      var lastRow = source.getMaxRows();
      var lastColumn = source.getMaxColumns();    
      range = source.getRange(1, 1, lastRow, lastColumn);
    } else {
      range = source;
    }
    data = range.getValues();
    for(var i = 0, iLen = data.length; i &lt; iLen; i++) {
      for(var j = 0, jLen = data[0].length; j &lt; jLen; j++) {
        if(!data[i][j]) {
          data[i][j] = 0;
        }
      }
    }  
    range.setValues(data);
  }
  </code></pre>