+ Reply to Thread
Results 1 to 5 of 5

Thread: VBA to define current selection as a named range?

  1. #1
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    242

    VBA to define current selection as a named range?

    I understand that this is probably pretty easy, I just dont know how to do it. So please excuse my ignorance on this. I am trying to teach myself.

    This is another thread that I started and with the help of another memeber, they were able to write a code that works just the same I want it to per my request....now I want to take it one step further. Thread is here: http://www.excelforum.com/excel-prog...html?p=2674591

    This code just selects a cell range.

    Now I just want to define or name that range as if I were going to go to FORMULAS > NAME MANAGER > NEW. ....to define it as 'SAMPLENAME'

    How do I code that?

    Im assuming it goes after:
    .MergeArea.Offset(, 3).Resize(rows_count, 1).Select
    Last edited by clemsoncooz; 01-04-2012 at 04:55 PM.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: VBA to define current selection as a named range?

    Try

    ThisWorkbook.Names.Add Name:="SampleName", _ 
    RefersTo:=Selection, Visible:=True
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: VBA to define current selection as a named range?

    You can also use
    selection.name = "SAMPLENAME"
    Good luck.

  4. #4
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: VBA to define current selection as a named range?

    Thanks to the both of you!

    And to clear it out would be:
        ActiveWorkbook.Names("SAMPLENAME").Delete
    Correct?

    is there a way to clear ALL the names ?

  5. #5
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: VBA to define current selection as a named range?

    hi clemsoncooz, option to make it:

    For Each nm In ActiveWorkbook.Names
            nm.Delete
    Next

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0