ivan_pozdeev
ivan_pozdeev

Reputation: 36008

Check if the Range is a Named Range

By Worksheet.Range("Name"), I can get a named range.

I'm looking for the reverse operation: given a Range, check if it has a defined name.

Tried .Name but it gives an expression rather than the user-defined name:

? SheetDB.Range("VerPeriod").Address
$C$1
? SheetDB.Range("$C$1").Name
=БазаСИ!$C$1

The intent is: I'd like to get a value from a given row by a column's user-defined name rather than its location to improve code readability and maintainability. For that, I'd make every header cell a named range. This can be implemented with a class module, so it's possible in the set-up code to scan the header row and make a hash table {name: column number}. (Leaving aside how much warranted this optimization is, the question remains.)

Upvotes: 0

Views: 1173

Answers (1)

MacroMarc
MacroMarc

Reputation: 3324

You were just a property away.

When you write SheetDB.Range("$C$1").Name, you are returned a Name object.

The property of the Name object that you want is actually the Name property of that Name object.

So:

SheetDB.Range("$C$1").Name.Name will give you "VerPeriod" as you want

Upvotes: 4

Related Questions