本文介绍了传递Range参数时出错424的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是VBA的新手,而且我使用这个非常简单的代码发生错误:
I am new to VBA, and I am having an error with this very simple code:
Sub sub1()
Dim myCell As Range
Set myCell = Sheet1.Cells(2, 2)
sub2 (myCell) '<<<<------- Error 424
End Sub
Sub sub2(x As Range)
'not doing anything yet
End Sub
我正在从 sub>
中收到错误424
code> SUB1 。在我看来,这应该起作用,因为 myCell
是一个范围...任何想法?
I am receiving Error 424
when invoking the sub2
from sub1
. In my mind, this should work, since myCell
is a Range... any idea?
推荐答案
删除括号,或添加调用
ie:
Ty removing either removing the brackets, or adding a Call
ie:
Sub Opt1()
Dim myCell As Range
Set myCell = Sheet1.Cells(2, 2)
sub2 myCell
End Sub
Sub sub2(x As Range)
MsgBox x.Address
End Sub
或
Sub Opt2()
Dim myCell As Range
Set myCell = Sheet1.Cells(2, 2)
Call sub2(myCell)
End Sub
Sub sub2(x As Range)
MsgBox x.Address
End Sub
这篇关于传递Range参数时出错424的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!