0

I've done some searches but can't find anything to suit/can't get the snippets to work with my code. I have the table below that is querying a number of ranges elsewhere on the sheet, any overdue actions arrive here and form a list, so this is a dynamic range as it gets larger/smaller.

I then have a script that will work through these rows and add an 'overdue' note in column L, the script should then grab that range marked as overdue, wrap in an email and send to the email receipients, the issue is the script is failing on the initial marking sequence, it is only supposed to mark 'overdue' up until the last row, but because there is formula dragged down in column 'K' to row 100, it thinks the last_row is 100 and therefore script fails because the other columns it's trying to retrieve are blank.

I have removed the data as it's sensitive but I'd like to get the last row by use a column of whole text as a reference for example column A, so even if there is formula dragged down in column K, it will ignore that because the whole text stops at a certain point in row A.

Table below:

Table

    function doOverdueCheck()
{
  var sheet = SpreadsheetApp.getActiveSheet();
  var data_range = sheet.getDataRange();
  var last_row = data_range.getLastRow();
  var today= new Date();
  today.setHours(0,0,0,0);
  
  sheet.getRange('L:L').clearContent();
  for(var r=2;r<=last_row;r++)
  {
    var inv_date = data_range.getCell(r,9).getValue();
    inv_date.setHours(0,0,0,0);
    if(today > inv_date)
    {
      sheet.getRange(r, 12).setValue("overdue");
    }
  }
}

It breaks on row 21 of the script and says inv_date is not a valid function because it's reached a blank row and can't turn a date into setHours(0,0,0,0) as there is no due date there, only formula in column K.

Any help is really appreciated.

Sam.Palf
  • 39
  • 5
  • You can use getColumnHeight() in [this answer](https://stackoverflow.com/a/55344474/7215091) – Cooper Jan 26 '22 at 18:30

0 Answers0