Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Dale Matthews   on Jan 26 In MS Office Category.

  
Question Answered By: Tyler Thompson   on Jan 26

You can look through the collection of range names, or you can cheat. :-)

If you put

On Error Resume Next

just before your Set statement, and

On Error Resume 0

just after the Set statement to turn error checking back on, the Set statement
will do nothing if the range doesn't exist. You'll then be able to test it,
probably with

If MyCell Is Nothing Then ...

(but that might not be exactly the right If).

If you want to do it properly, the following function  is from my library

Public Function NamedItemExists(ByVal ItemName As String) As Boolean
Dim Item As Variant
On Error GoTo DoesntExist
Item = Application.Range(ItemName)
NamedItemExists = True
Exit Function
DoesntExist:
NamedItemExists = False
End Function

Oops - I cheated too. :-( But at least I hid it in a
function. :-)

So

If Not NamedItemExists ("MyRangeName") Then
MsgBox ("Houston, we have a problem")
End If

However, you can use the Application.Names collection if you want to know
explicitly what range names there are.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 


Tagged: