Excel VBA:“excel vba 运行时错误 1004”应用程序定义或对象定义错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18206022/
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
Excel VBA: 'excel vba run-time error 1004' application-defined or object-defined error
提问by user2674568
I have this line in a module and it keeps spitting up a run-time error 1004 when I try and run it.
我在一个模块中有这一行,当我尝试运行它时,它不断地吐出运行时错误 1004。
Can anyone help?
任何人都可以帮忙吗?
I'm guessing it's to do with how the Range is referenced, but i'm not sure. This is all new to me.
我猜这与 Range 的引用方式有关,但我不确定。这对我来说都是新的。
rngFirst = ThisWorkbook.Worksheets("Still In Progress").Range("G" & 1 & ":G" & lw)
Many thanks in advance
提前谢谢了
回答by Dave
This works for me:
这对我有用:
Sub Button1_Click()
Dim rngFirst As Range
Dim int1 As Integer
int1 = 2
Set rngFirst = ThisWorkbook.Worksheets("Sheet1").Range("G" & 1 & ":G" & int1)
rngFirst.Select
End Sub
I was getting the same error as you until I used Dim and Set.
在我使用 Dim 和 Set 之前,我遇到了和你一样的错误。
回答by mcalex
Your range is not defined correctly. Essentially, you are setting the range to:
您的范围定义不正确。本质上,您将范围设置为:
"Still In Progress!G1:G1w".
“仍在进行中!G1:G1w”。
You need to set the last bit of the rngFirst formula to a number (eg at the bottom right hand corner of the range). Something like:
您需要将 rngFirst 公式的最后一位设置为一个数字(例如,在范围的右下角)。就像是:
...Range("G" & 1 & ":G" & 20)
...Range("G" & 1 & ":G" & 20)
if the bottom of your data is at row 20.
如果您的数据底部位于第 20 行。