title: Random substring error? "TypeError: Cannot find function substring in object..."
body: <p>The error is:</p>
  
  <p><strong>TypeError: Cannot find function substring in object</strong></p>
  
  <p>The code loops through 10 values, checking for the first character being a number.</p>
  
  <pre><code>function TypeErrorMystery() {
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var s = ss.getActiveSheet();
  
    //loop from cell 1-10
    for (var i = 0; i &lt; 10; i++) {
      var range = s.getRange(i + 1, 1)
      var substring1 = range.getValue().substring(0, 1);
        //if first character in cell is #
        if (substring1 === "#" ) {
           //write over it with "success"
           range.setValue("success");
        }
     };
  }
  </code></pre>
  
  <p>The exact error is:</p>
  
  <p><strong>TypeError: Cannot find function substring in object 3. (line 9, file "Code")</strong>,</p>
  
  <p>where line 9 is:</p>
  
  <pre><code>var substring1 = range.getValue().substring(0, 1);
  </code></pre>