iamlaosong文
常用下面方式取得Excel工作表的有效行数,前者是2003版,后者是2007版:
(1)MaxRow = sheets(1).[A65536].End(xlUp).Row
(2)MaxRow = sheets(1).[A1048576].End(xlUp).Row
1、在不知道版本的情况下,一种方法是判断文件版本或者文件扩展名,另一种方法简单通用,就是取Excel表格的最大行列数,然后根据这个行列数取有效行列数,取有效行数语句如下:
ExcelRowNo = Rows.Count
MaxRow = Sheets(1).Range("A" & ExcelRowNo).End(xlUp).Row
即:
MaxRow = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
或者,换种写法:
MaxRow = Sheets(1).Cells(rows.Count, 1).End(xlUp).Row
对当前工作表,写法如下:
MaxRow = Range("A" & Rows.Count).End(xlUp).Row
或者
MaxRow = Cells( Rows.Count,1).End(xlUp).Row
2、同样,取有效列数也可以采取同样的办法:
ExcelColNo = Columns.