I have a Google Script for a "leaderboard" type page, where vlookup formulas and such give each user an overall score on a single tab. I check the column (B) that has the user names, and find the last row that is populated, create a range that selects from column B to column AC and sorts by descending score order, followed by user name. I found the way to get the last row populated here, and read about the fact that I have to move forward one row somewhere else I cannot find again right now.
HOWEVER, it is not including the bottom user in the sort. I have tried doing other things to the selected range and it does include that last row (for example, the setBackground shown below colors in the proper range). I feel like it's somehow related to the +1 and how it deals with integer vs. string, but I can't find the right combination.
NOTE: There are no frozen panes on the sheet. I checked that.
var avalsnew = xpdoc.getRange('b2:b').getValues();
//I've tried both b1 and b2 here
var alastnew = avalsnew.filter(String).length;
alastnew = parseInt(alastnew) + 1;
//Tried with and without this line, which is why I suspect this is part of the problem
var percentsort = percentdoc.getRange('b2:ac' + alastnew);
percentsort.setBackground('green');
//this includes the last row
percentsort.sort([{column: 29, ascending: false}, {column: 2, ascending: true}]);
//but this does not