查找最后使用的行的更好方法 [英] Better way to find last used row

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

问题描述

我正在尝试通过这种方式找到最后一列,即找到最后一行:

I am trying to make this way of finding the last row as I found the last column:

Sheets("Sheet2").Cells(1,Sheets("Sheet2").Columns.Count).End(xlToLeft).Column`enter code here`

我知道该怎么做,但是它没有以前的帮助:

I know how to do it this way but it is not as helpful as the prior would be:

u = Sheets("Sheet1").Range("A65536").End(xlUp).Row

我尝试这样做:

Sheets("Sheet2").Cells(Sheets("Sheet2",1).Rowa.Count).End(xlToUP).Column

任何帮助将不胜感激.

Any help would be greatly appreciated.

简介:想对最后一行再次按以下方式进行.谢谢

Synopsis:Would like the below way again for last row. Thanks

Sheets("Sheet2").Cells(1,Sheets("Sheet2").Columns.Count).End(xlToLeft).Column`enter code here`

推荐答案

您应该使用with语句来限定您的RowsColumns计数.这样可以防止在使用2007年之前的较早版本和2007年的较新版本的Excel工作簿时出现任何错误.

You should use a with statement to qualify both your Rows and Columns counts. This will prevent any errors while working with older pre 2007 and newer 2007 Excel Workbooks.

最后一列

With Sheets("Sheet2")
    .Cells(1, .Columns.Count).End(xlToLeft).Column
End With 

最后一行

With Sheets("Sheet2")
    .Range("A" & .Rows.Count).End(xlUp).Row
End With 

With Sheets("Sheet2")
    .Cells(.Rows.Count, 1).End(xlUp).Row
End With 

这篇关于查找最后使用的行的更好方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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