Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    returning Range names (2000)

    When I select a named range, the code:
    Msgbox Selection.Name
    returns an address. like (=Sheet1!B4:B5)

    How do I get the NAME of the selection?

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: returning Range names (2000)

    Not easily:

    <pre>Option Explicit

    Sub test()
    Dim onm As Name
    Dim oSel As Range
    Dim sAddr As String
    Set oSel = Selection

    If TypeName(oSel) <> "Range" Then
    MsgBox "No cells selected"
    Exit Sub
    End If
    For Each onm In ActiveWorkbook.Names
    On Error Resume Next
    sAddr = onm.RefersToRange.Address
    If sAddr = oSel.Address Then
    MsgBox "Range " & oSel.Address & " is named: '" & onm.Name & "'"
    Exit Sub
    End If
    Next
    End Sub
    </pre>

    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: returning Range names (2000)

    Thanks Jan

    this RefersToRange method is new to me

    You'd think MS could come up with and easier way to get range names from vba.

    How else is this method used?

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: returning Range names (2000)

    It is not a method. It is a property of a named object when the name refers to a range.

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •