Determining the last row in a single column

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

    Although there is no straighforward formula, I can think of, it doesn't require dozens of lines of code to find out the last row in column A. Try this simple function. Use it in a cell the normal way you'd use some other function =CountColA()

    function CountColA(){
      var sheet = SpreadsheetApp.getActiveSheet();
      var data = sheet.getDataRange().getValues();
      for(var i = data.length-1 ; i >=0 ; i--){
        if (data[i][0] != null && data[i][0] != ''){
          return i+1 ;
        }
      }
    }
    

提交回复
热议问题