我是VBA的新手,我在这个非常简单的代码中遇到错误:
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
我从Error 424
调用sub2
时收到sub1
。在我看来,这应该有效,因为myCell
是一个范围...任何想法?
答案 0 :(得分:3)
删除括号,或添加Call
即
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