gpt4 book ai didi

excel - 找到最后使用的行的更好方法

转载 作者:行者123 更新时间:2023-12-02 00:34:57 24 4
gpt4 key购买 nike

我试图以与找到最后一列相同的方式找到最后一行:

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

我知道这种方法,但它不如以前的方法有用:

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

我尝试过:

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

概要:我希望最后一行采用以下方式。

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

最佳答案

您应该使用 with 语句来限定您的 计数。这将防止在使用 2007 年之前的旧版和 2007 年新版 Excel 工作簿时出现任何错误。

最后一栏

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

关于excel - 找到最后使用的行的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38882321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com