确定单个列中的最后一行 [英] Determining the last row in a single column

查看:117
本文介绍了确定单个列中的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张数据表,里面有数据 A H

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

我需要确定包含数据的列 A 中的最后一行(它们都是连续的 - 数据/行中没有空白)。

I need to determine the last row in column A that contains data (it's all contiguous - no gaps in the data/rows).

其他列中的数据还有比列 A 更多的行数据,所以我只需要隔离列 A 。 (和/或仅在col A 内)范围内。

There is also data in the other columns that have more rows of data than column A, so I need to isolate only column A. (And/or just a range within col A).

我可以在电子表格级别使用

I can do this on the spreadsheet level using

=COUNTA(A2:A100)

然而,在我所有关于Google Apps脚本解决方案的研究中,找到需要执行包含数十行代码的多个函数 - 包括大量的 i ++ 的东西...我可以通过直接从 A1

However in all of my researching for a Google Apps Script solution, all I seem to find are requirements to perform multiple functions encompassing dozens of lines of code - including plenty of i++ stuff... Which I could do less complexly via offsetting directly from A1.

有没有可能以特定列的方式修改此方法?

Is there possibly a column-specific way of modifying this method?

var aLast = ss.getDataRange().getNumRows();

如果一个复杂的过程是需要的,那就这样吧。但我发现很难想象(甚至更难找到!)一个更简单的解决方案。

If a convoluted process is what is required, then so be it. But I find it difficult to imagine (and even more difficult to find!) a simpler solution.

有人会照顾我吗(或者让我泡个泡泡)?

Does anyone care to enlighten me (or pop my bubble)?

推荐答案

使用JavaScript技巧怎么样?

How about using a JavaScript trick?

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

我从这个答案 Array.filter( )方法在> Avals 数组上运行,该数组包含列A中的所有单元。通过对本机函数的构造函数进行过滤,我们只返回非null元素。

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.

这仅适用于单列;如果范围包含多个列,那么 filter()的结果将包含所有列的单元格,因此不在该范围的已填充维度之内。

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.

这篇关于确定单个列中的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆