Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

name of range, cells

Status
Not open for further replies.

calvi

Technical User
May 26, 2003
87
NL
How do I make a condition to check whether the range I validate are a defined name or do not have a defined name.
Something like this?
If Cells(1, 1) has a defined name Then
' do this
Else
' do another
End If

or smth like this?
dim rng as Range
If rng.Name Is Nothing Then
' do this
Else
' do another
End If
 




Hi,

There is Names collection.

The Name object has, as it's Parent property the Worksheet object, and not a Range object, as you might have guessed. However, the Name object has a RefersTo property. I'd suggest that you use the Watch Window faq707-4594, in order to discover how this might help you.

Step thru this code and use the Watch Window...
Code:
dim nm as name
for each nm in thisworkbook.names
   msgbox mn.parent
   msgbox nm.name
   msgbox nm.refersto
next

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
I actually want to know whether a cell or range is defined with name or not. if yes do this if not do that.

Public Sub Workout(rng as Range)
'condition if rng has name the do this
'else if rng has no name defined do that.
end sub

So that I can call this function/procedure:
call Workout Cells(40, 6) or
call Workout Range("rangename")
 
MsgBox YourRange.Name.Name
You need error trapping, the above code fails if there is no name assigned to YourRange object.

combo
 
combo: that way is a workaround, but it works. I catch the Err.Number, On Resume Next. thx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top