+ Reply to Thread
Results 1 to 4 of 4

Trouble with the [worksheet].Names-collection!

  1. #1
    Registered User
    Join Date
    05-23-2007
    Posts
    9

    Trouble with the [worksheet].Names-collection!

    Hi all!

    I was trouble-shooting one of my (two year old) Excel VBA projects and I bumped into the following: I needed to view all the defined names for each sheet in a workbook. So I typed the following sub

    Please Login or Register  to view this content.
    This gives me names like 'Diagnos 2'!max_poang. However, I should have gotten 'Diagnos 1'!max_poang too! I know the name is there, since when on the sheet 'Diagnos 1' I type max_poang in the cellref-field (upper left corner), the desired range is selected (on the sheet 'Diagnos 1').

    Why then doesn't this name show up when I list all the names in all the worksheets? Can I still reference the range as usual when programming? Anyone knows what's wrong here?

    Uffe

  2. #2
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Re: Trouble with the [worksheet].Names-collection!

    The problem is that the macro is designed to search for Names that are LOCAL to a sheet and not GLOBAL to the workbook. Previously, it worked because the Names were setup as LOCAL names. Now, your max_poang range name is a GLOBAL range name and the macro, as is, won't work.
    If you step thru the macro, you'll find that 'aSheet.Names.Count' is always ZERO for every iteration. That's because, this format (& the 'aSheet.Names(namnNr).Name' text) is designed for names assigned to a specific sheet (a LOCAL name).

    If you don't know what I mean by dfferentiating between LOCAL & GLOBAL range names this is understandable, as the MS Range Name editor is so sorely lacking that this almost impossible to discern using MS tools only ().
    To make this understandable & to help you manage these Range Names, I highly suggest that you download & install the following free download. It is extremely powerful in managing Range Names: LINK

    The following altered code will pick up all of your range names, but since the names in your file are GLOBAL, you won't see the 'Diagnos 2'! prior to the name as, being GLOBAL, the the names are not assigned to a specific sheet. And, the name will show up repetitively for each & every sheet iteration.

    OR, You can use the above download utility to change the names to LOCAL, and then your code will work as you already have it. But, warning (), if you change a name to LOCAL, then it can only be "seen" within that sheet and not "visible" by the other sheets. Only do this if other sheets don't access this range name.
    Please Login or Register  to view this content.
    Last edited by sauerj; 05-25-2011 at 10:05 PM.

  3. #3
    Registered User
    Join Date
    05-23-2007
    Posts
    9

    Re: Trouble with the [worksheet].Names-collection!

    Please Login or Register  to view this content.
    Ok - got it!

    I have copies of sheets and I use the same names on each. Perhaps I was not careful enough when defining the names the first time, and that's why some are global and some are local? I guess, from what you wrote, that code will run properly anyway if the reference to the actual sheet is there, since the named range is properly selected when typing for example max_poang - even on the sheet 'Diagnos 1'!

    Thanks a lot! I was a bit confused there for a while!

  4. #4
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Trouble with the [worksheet].Names-collection!

    Also Name Manager is a wonderful tool to work with names. You can get it from
    http://www.jkp-ads.com/officemarketplacenm-en.asp
    regards

    johnjohns

    When you are not sure where to go, every road takes you there!

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