Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jul 2002
    Location
    Sacramento, CA
    Posts
    193
    Thanks
    3
    Thanked 1 Time in 1 Post
    Could someone point me to or provide an example of how to define a new named range based on an active worksheet selection? The name will come from a VBA string variable.

    Thanks.
    Marty



  2. #2
    5 Star Lounger
    Join Date
    Aug 2004
    Location
    Connecticut, USA
    Posts
    816
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something like this:
    Code:
    ub name()
    Dim myRange As Range, myString As String
    myString = "Scores"
    Set myRange = Selection
        Names.Add name:=myString, RefersToR1C1:=myRange
    End Sub

  3. #3
    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
    Another way would be:

    Code:
    Sub NameRange()
      Dim sName As String
      sName = "NewName"
      Selection.Name = sName
    End Sub
    Steve

  4. #4
    2 Star Lounger
    Join Date
    Jul 2002
    Location
    Sacramento, CA
    Posts
    193
    Thanks
    3
    Thanked 1 Time in 1 Post
    Thanks for the input. Tried both methods and each worked great.

    Marty

Posting Permissions

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