VBA 运行时错误 424:需要对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39514669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 11:17:13  来源:igfitidea点击:

VBA Run time error 424: Object required

vbaobjectrequired

提问by BVS

I have a simple code to find first and last row populated in excel. When I execute this I get error VBA Run time error 424: Object required. I searched other 424: object required errors but it doesn't give specifics on this particular logic. I tried Lf both as integer and string.

我有一个简单的代码来查找填充在 excel 中的第一行和最后一行。当我执行这个时,我收到错误 VBA 运行时错误 424:需要对象。我搜索了其他 424: object required 错误,但它没有提供有关此特定逻辑的详细信息。我试过 Lf 作为整数和字符串。

Sub lastrow()
Dim Lf As Integer
Lf = sht.Cells(sht.Rows.Count, Range("Lastrow").Column).End(xlUp).Row
End Sub

Can anyone please help with this?

任何人都可以帮忙吗?

回答by BVS

I resolved this error by activating worksheet as below:

我通过激活工作表解决了这个错误,如下所示:

Dim sht As Worksheet
Set sht = ActiveWorkbook.ActiveSheet