How do you get a Range to return its Name?

GenericJam picture GenericJam · Sep 2, 2010 · Viewed 39.1k times · Source
Dim sampleRange as Range
Set sampleRange = Worksheet.Range(Cells(1,1),Cells(1,4)
sampleRange.Name = "Range1"
MsgBox sampleRange.Name

The above code will show the actual address of the range, not the name. Why?
How do I get a named range to return its name?

Answer

Lance Roberts picture Lance Roberts · Sep 2, 2010

For a Range, Name isn't a string it's a Name object, that you then take the Name property of to get the string:

MsgBox sampleRange.Name.Name