Determining the last row in a single column

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

    How about using a JavaScript trick?

    var Avals = ss.getRange("A1:A").getValues();
    var Alast = Avals.filter(String).length;
    

    I borrowed this idea from this answer. The Array.filter() method is operating on the Avals array, which contains all the cells in column A. By filtering on a native function's constructor, we get back only non-null elements.

    This works for a single column only; if the range contains multiple columns,then the outcome of filter() will include cells from all columns, and thus be outside the populated dimensions of the range.

提交回复
热议问题