Determining the last row in a single column

前端 未结 19 1651
野性不改
野性不改 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:08

    personally I had a similar issue and went with something like this:

    function getLastRowinColumn (ws, column) {
      var page_lastrow = ws.getDataRange().getNumRows();
      var last_row_col = 0
      for (i=1; i<=page_lastrow;i++) {
        if (!(spread.getRange(column.concat("",i)).isBlank())) {last_row_col = i};
      }
      return last_row_col
    }
    

    It looks for the number of rows in the ws and loops through each cell in your column. When it finds a non-empty cell it updates the position of that cell in the last_row_col variable. It has the advantage of allowing you to have non-contiguous columns and still know the last row (assuming you are going through the whole column).

提交回复
热议问题