First Empty Row in Google Script with dinamic column range

I’m trying to get the first empty row of a column. The number of this column is determined by a variable.

var values = pnl.getRange('A:A').getValues();      //Returns 2D array
var firstEmptyRow = 4;
while(values[firstEmptyRow]&&values[firstEmptyRow][0]!=""){
  firstEmptyRow++;
}
firstEmptyRow++;

pnl.getRange(firstEmptyRow,1+24*month).setValue(firstEmptyRow);

This works fine, however in this function the range of the column is always the same.
Here is what i’m trying to do

var lastRow = pnl.getLastRow()
var columnRange = pnl.getRange(4,1+24*month,lastRow,1);

var values = columnRange.getValues();      //Returns 2D array?
var firstEmptyRow = 4;
while(values[firstEmptyRow]&&values[firstEmptyRow][0]!=""){
  firstEmptyRow++;
}
firstEmptyRow++;

pnl.getRange(firstEmptyRow,1+24*month).setValue(firstEmptyRow);

I don’t get any errors, the code simply dosn’t work.

15 thoughts on “First Empty Row in Google Script with dinamic column range”

Leave a Comment