用VBA得到EXCEL表格中的行数和列数
(2016-07-02 10:46:07)
标签:
it |
分类: Excel应用 |
每种方法中上面的是Excel的行数,下面的是Excel的列数。
方法1:
ActiveSheet.UsedRange.Rows.Count
ActiveSheet.UsedRange.Columns.Count
方法2:
ActiveSheet.Range("A65535").End(xlUp).Row
ActiveSheet.Range("IV1").End(xlToLeft).Column
可以简写为:
ActiveSheet.[A65536].End(xlUp).Row
ActiveSheet.[IV1].End(xlToLeft).Column
方法3:
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
缺点:在工作表进行对删除或清除操作时也会变得比实际情况大。
方法4:
ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
缺点:在工作表进行对删除或清除操作时也会变得比实际情况大。
方法5:
Application.CountA(ActiveSheet.Range("A:A"))
Application.CountA(ActiveSheet.Range("1:1"))
只能统计一列(行)的实际使用情况,得到的不一定是最后一行(列)的位置。方法2的数值比此方法大时,说明在A列的数据间有空白未填写的单元格。
方法6:
ActiveSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
ActiveSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
效果同方法2
以上方法中比较常用的是方法1和方法2。
自己测试过,这个好用。
Dim

加载中…