在VBA中调用sub中的函数 - 限定符错误

时间:2017-01-19 04:28:07

标签: vba excel-vba excel

我想在我的VBA代码中更加“面向对象”。但是,我无法将变量传递给函数。在这里,我在IsEmpty函数上收到了无效的限定符错误消息。

如何更正我的代码?

Sub test_too_much_data()

If toomuchdata("Data input", "B1018") = False Then
    MsgBox ("Sorry, the tool can only accomodate 1000 rows.")
    Exit Sub
End If

End Sub


Function toomuchdata(sheet As String, range As Variant) As Boolean
    toomuchdata = IsEmpty(Sheets("String")).range(range)
End Function

谢谢!

1 个答案:

答案 0 :(得分:0)

将您的Function代码更新为以下内容:

Function toomuchdata(sheetStr As String, RngStr As String) As Boolean
    toomuchdata = IsEmpty(Sheets(sheetStr).Range(RngStr).Value)
End Function
相关问题