title: How to fix "Exception: The number of rows in the range must be at least 1 while running splitTextToColumns(' ')"
body: <p>My initial data range is a sheet of seven columns and a variable number of rows. </p>
  
  <p>I am only interested in column 5 (E) which contains text like</p>
  
  <pre><code>21 BCN SJP[WR] -COR(WR) PPG ST 06/05 23:45 ( HAPA-95%-P-15/04 )
  </code></pre>
  
  <p>I am trying to split this text into columns using a space delimiter. After splitting, I will rearrange the columns into a preferred order. </p>
  
  <p>My code so far is: </p>
  
  <pre><code>function mnEmpties() {  
    var ss = SpreadsheetApp.getActive();
    var sheet = ss.getSheetByName("M/N Empties");
    sheet.deleteRow(2);
    sheet.setFrozenRows(2);  
  
    var maxRows = sheet.getMaxRows(); 
    var lastRow = sheet.getLastRow();
    var lastColumn = sheet.getLastColumn(); 
  
    var range1 = sheet.getRange(3,5,lastRow);//first 02 rows are header values, problematic range
    range1.splitTextToColumns(' '); 
  
  var range = sheet.getRange("F:F"); 
   range.setValues(range.getValues().map(function(row1) {
    return [row1[0].replace("BOXNHL", "BOXN")];
   }));
  
  // //USING THE SAME RANGE
    range.setValues(range.getValues().map(function(row2) {
    return [row2[0].replace("BTFLN", "BTPN")];
   }));
  
    var values1 = sheet.getRange(3,7,lastRow).getValues(); 
    var values2 = sheet.getRange(3,8,lastRow).getValues();   
    var results1 = []; 
    for(var i=0; i&lt;lastRow; i++){
      results1[i] = [values1[i][0]+""+values2[i][0]];
    }
    sheet.getRange(3,7,lastRow).setValues(results1); 
  
    var values3 = sheet.getRange(3,11,lastRow).getValues(); 
    var values4 = sheet.getRange(3,12,lastRow).getValues();   
    var results2 = []; 
    for(var i=0; i&lt;lastRow; i++){
      results2[i] = [values3[i][0]+""+values4[i][0]];
    }
    sheet.getRange(3,11,lastRow).setValues(results2); 
  
    var lastRow = sheet.getLastRow();  
    var insert1 = sheet.getRange(3,6,lastRow).getValues();
    sheet.getRange(3,1,lastRow).setValues(insert1);
  
    var insert2 = sheet.getRange(3,5,lastRow).getValues();
    sheet.getRange(3,2,lastRow).setValues(insert2); 
  </code></pre>
  
  <p>Every time I run this code there is an error message:</p>
  
  <pre><code>Exception: The number of rows in the range must be at least 1 (for code line var range1 = sheet.getRange(3,5,lastRow);)
  </code></pre>
  
  <p>and the script doesn't continue. I tried changing the range values many times, but to no avail. </p>