Determining the last row in a single column

前端 未结 19 1617
野性不改
野性不改 2020-11-22 10:46

I have a sheet with data in cols A through H.

I need to determine the last row in column A that contains data (it\'s all conti

19条回答
  •  忘掉有多难
    2020-11-22 11:00

    You can do this by going in the reverse way. Starting from the last row in spreadsheet and going up till you get some value. This will work in all the cases even if you have some empty rows in between. Code looks like below:

    var iLastRowWithData = lastValue('A');
    function lastValue(column) {
      var iLastRow = SpreadsheetApp.getActiveSheet().getMaxRows();
      var aValues = SpreadsheetApp.getActiveSheet().getRange(column + "2:" + column + lastRow).getValues();
    
      for (; aValues[iLastRow - 1] == "" && iLastRow > 0; iLastRow--) {}
      return iLastRow;
    }
    

提交回复
热议问题