Error: the starting row of the range is too small

10,712 views
Skip to first unread message

kelo...@sewanee.edu

unread,
Jun 15, 2022, 4:59:25 PM6/15/22
to Google Apps Script Community
Hi Everyone,

I've used the following code successfully for years and I am now receiving an error message around line 46 that states the following: "the starting row of the range is too small".

I've highlighted the row in question. 

Can someone please help understand what the issue is?

Here is the code:

function addStudents() {
  //Get the spreadsheets and data from the spreadsheets
  var sa = SpreadsheetApp.getActiveSpreadsheet();
  var slateSS = sa.getSheetByName("From Slate 2022");
  var studentSS = sa.getSheetByName("Students to Merge");
  var slateDT = getDataValues(slateSS.getName());
  var studentDT = getDataValues(studentSS.getName());
  var additions = [];
  var rows;
  
  var i = 0;
  while(i < studentDT.length) {
    if(studentDT[i][1] == "") {
      rows = i;
      i = 1000;
    }
    i++
  }
  
  //Loop through all of the data coming from Slate
  for(i = 1; i < slateDT.length; i ++) {
    var bannerid = slateDT[i][1];
    var match = "No Match";
    var j = 1;
    
    //Loop through all of the data unless there is a match
    while(j < studentDT.length && match == "No Match") {
      var matchID = studentDT[j][2].trim();

      if(bannerid.trim() != matchID){ //If the BannerIDs don't match, move on
        j++;
      } else {
        match = "Match"; //If the BannerIDs do match, stop the loop
      }
    }
    
    if(match == "No Match"){ //If there was no match, add it to the additions array without the last three columns
      additions.push(slateDT[i].splice(0,5));
    }
  }
  
  var help = 1;
  
  if(additions.length > 0) {
    //Paste these into the bottom of the first page starting in column 2
    studentSS.getRange(rows+1, 2, additions.length, additions[0].length).setValues(additions);
  }
  
  //markWithdrawals();
}

Thank you,

Kerline

cbmserv...@gmail.com

unread,
Jun 15, 2022, 6:30:01 PM6/15/22
to google-apps-sc...@googlegroups.com

Most likely issue is value of variable rows is incorrect. Variable rows seems to be defined based on the amount of rows in array studentDT and that array is defined in a function called getDataValues which you have not shared of what it does.

 

Add a line above the error as follows to see what is the content of rows:

 

Logger.log(rows);

 

That should give you a view of what is the value of rows.

 

Alternatively, share with us the code which contains the function getDataValues so we can see how the data is filled in for any issues.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a04a71fd-196e-4ebc-952f-febd91390eban%40googlegroups.com.

kelo...@sewanee.edu

unread,
Jun 28, 2022, 12:57:17 PM6/28/22
to Google Apps Script Community
Got it! Thank you, George.

Adam Graham

unread,
Oct 13, 2022, 11:09:11 AM10/13/22
to Google Apps Script Community
If I don't understand any coding, what can I do here?   I am having the same issue
Reply all
Reply to author
Forward
0 new messages