如果范围存在,则为文本Excel VBA

我想testing一个范围是否存在能够创build以下模式:

if not exists(r) then MsgBox("Range is missing") end if Function exists(r as range) as boolean End function 

这里是我想testing一个范围的例子,如果它存在与否

 Call RangeExists(lob.ListColumns("Leverera utt").DataBodyRange) 

我怎样才能做到这一点?

你可以这样做:

 Sub CheckRange() Dim myRange As Variant myRange = InputBox("Enter your name of your range") If RangeExists(CStr(myRange)) Then MsgBox "True" Else MsgBox "No" End If End Sub 

而function:

  Function RangeExists(s As String) As Boolean On Error GoTo No RangeExists = Range(s).Count > 0 No: End Function