Determining the last row in a single column

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

    I rewrote the getLastRow/getLastColumn functions to specify a row index or column index.

    function get_used_rows(sheet, column_index){
          for (var r = sheet.getLastRow(); r--; r > 0) {
            if (sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getCell(r, column_index).getValue() != ""){
              return r;
              break;
            }
          }
        }
    
    function get_used_cols(sheet, row_index){
      for (var c = sheet.getLastColumn(); c--; c > 0) {
        if (sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getCell(row_index, c).getValue() != ""){
          return c;
          break;
        }
      }
    }
    

提交回复
热议问题