I'm trying to automate adding new rows if I'm on the last few rows of my sheet. It works, but since I'm also adding a cell reference to it, and checking the amount of free rows left using getMaxRows-getLastRow, it is always assuming that I have no free rows, so it adds another row.
edit : My last row and last column have that reference number, so I'm simply incrementing that last number.
Here is my function that is executed once a cell is modified :
function autoAddRows()
{
var s = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lastRow = s.getLastRow();
var maxRow = s.getMaxRows();
var lastColumn = s.getLastColumn();
var lastVkey = s.getRange(lastRow,lastColumn,1,1).getValue();
if (maxRow-lastRow < 2) {
s.insertRowAfter(maxRow);
s.getRange(lastRow+1,lastColumn,1,1).setValue(lastVkey+1);
}
}
There has to be a better way?