+ Reply to Thread
Results 1 to 2 of 2

Refer to a Workbook level named range

  1. #1
    Registered User
    Join Date
    04-03-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    4

    Refer to a Workbook level named range

    I have two named ranges which share the same "label/name" at both the workbook level and the worksheet level. I need to refer to the one at the workbook level in VBA. How can I do that? Everytime I do it, it's referring to the first one listed which is the worksheet level one. Why and how? Actually what happened is I had one named range named "myRange" at the workbook level. But, when the user copied the sheet that name was applied to, Excel created another instance of that named range, but at the sheet level. I need the named range on my original sheet - the workbook level name in order for the rest of my code to work.

    Let's say you create a named range for cell A1 on "Sheet 1" named "myRange". Then, you copy that sheet which creates "Sheet 1 (2)". What Excel does (unless you can tell me a way to prevent this) is copy the "myRange" named range so that you now have one at the worksheet level too. So in the "Name Manger" you'll now see two named ranges sharing the same name at two levels:

    Name 1: myRange Scope: Sheet 1 (2)
    Name 2: myRange Scope: Workbook

    Then, if I do this:

    Debug.print ActiveWorkbook.Names("myRange").Parent

    It will return "Sheet1 (2)", but what I really want it to return is "Sheet 1"

    Thoughts?

    Your help is very appreciated!

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Refer to a Workbook level named range

    Sounds like you might be running into the bug mentioned halfway down this page: http://www.jkp-ads.com/Articles/ExcelNames10.asp

    Which sheet is active when you run your code?
    Everyone who confuses correlation and causation ends up dead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] What happens when I refer to a named range?
    By RogeratCCCC in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 04-21-2012, 04:06 PM
  2. Replies: 2
    Last Post: 01-10-2012, 07:33 AM
  3. Named Ranges that refer to all of workbook
    By dta1984 in forum Excel General
    Replies: 13
    Last Post: 01-06-2012, 12:20 PM
  4. VBA Refer to named range in different workbook
    By globalpontoon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-07-2010, 03:20 AM
  5. [SOLVED] named range ?::how to I refer to current workbook without using its name?
    By Rajni R in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-06-2005, 07:05 AM

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.6.0 RC 1