获取填充单元格数(VBA) [英] Getting the number of filled cells in a column (VBA)
问题描述
我刚开始使用Excel中的编程VBA来自动化一些令人讨厌的手动内容...所以这样会听起来像一个完全没有问题的问题,虽然我对VBA对象并不十分熟悉, / p>
所以我的quesstion:
有没有更优雅的方式来找出列的长度?我的第一列是一个索引,单调增加数字,结束于一个不可预测的点。
现在我想知道这个列有多少条目。有没有比迭代更好的方法,注意一个空单元格?
Greetz,
Poeschlorn
一种方法是:(假设索引列从A1开始)
MsgBox Range(A1)。End(xlDown).Row
哪个正在寻找第一个空闲的单元格从A1向下,并显示您的序号行号。
您可以选择下一个空单元格:
Range(A1)。End(xlDown).Offset(1,0).Select
如果需要数据集的结尾(包括空格),请尝试:Range(A:A)。SpecialCells(xlLastCell).Row
I'm just starting with "programming" VBA on Excel to automatize some anoying manual stuff...so this will probebly sound like a total nooby question, although I'm not very familiar to VBA Objects and so on.
So my quesstion: Is there a more elegant way to find out the length of a column? My first column is an index, with monotonously increasing numbers, which ends at a non predictable point. Now I want to find out, how many entries this column has. Is there a better way than iterating throug this and watch out for an empty cell?
Greetz, Poeschlorn
One way is to: (Assumes index column begins at A1)
MsgBox Range("A1").End(xlDown).Row
Which is looking for the 1st unoccupied cell downwards from A1 and showing you its ordinal row number.
You can select the next empty cell with:
Range("A1").End(xlDown).Offset(1, 0).Select
If you need the end of a dataset (including blanks), try: Range("A:A").SpecialCells(xlLastCell).Row
这篇关于获取填充单元格数(VBA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!