+ Reply to Thread
Results 1 to 11 of 11

Workbook Defined Name not available to other sheets

  1. #1
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Workbook Defined Name not available to other sheets

    Hi all;

    Are Defined Names attached to the workbook only available to macros when the Active sheet is the one in the Refers To?

    I have a Defined Name attached to the workbook (not to a sheet).
    Name : Strengths
    Refers To : =Data!$P$1


    When I'm in VBE with no macro running and active sheet is not Data I type ? Range("Strengths").Address in the immediate window and it correctly prints $P$1.

    Now I put a break in Worksheet_Change for every sheet. When it breaks I type ? Range("Strengths").Address in the immediate window, I get error 1004. Except in Data!Worksheet_Change. Then it correctly prints $P$1.

    How can I make a Defined Name attached to the workbook available to all macros?
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,309

    Re: Workbook Defined Name not availble to other sheets

    In a worksheet's code module, an unqualified reference to Range refers specifically to a range on the sheet containing the code. If the range is not on that sheet, then you'll get an error.
    Anyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Workbook Defined Name not availble to other sheets

    Hi,

    I think you need to specify the sheet name when using sheet events. i.e.
    Please Login or Register  to view this content.
    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Workbook Defined Name not available to other sheets

    So how can I refer to a name that is attached to the workbook from withing a macro?
    The only thing I can think of is to define a name for each sheet with the Refers To = the workbook name.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,309

    Re: Workbook Defined Name not available to other sheets

    Either qualify the Range call with the correct sheet, or use
    Please Login or Register  to view this content.
    If you know your workbook is active, you can also use
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by romperstomper; 07-20-2010 at 02:39 PM. Reason: corrected code

  6. #6
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Workbook Defined Name not available to other sheets

    Thanks romperstomper;

    application.range("blah") makes sense. Don't know why I didn't think of it.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,309

    Re: Workbook Defined Name not available to other sheets

    If you want to be safe, I'd use one of the first two options (I've just amended my code as my phone knocked off the RefersToRange part in the first code snippet).

  8. #8
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Workbook Defined Name not available to other sheets

    Yeah, I don't use the 3rd option. I'm working on the forum so much, I don't use shortcuts like that any more. The people I help don't know what they mean. It's just easier to use the code that they understand.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,309

    Re: Workbook Defined Name not available to other sheets

    Just to clarify, when I say the first two, I mean these:
    Quote Originally Posted by romperstomper View Post
    Either qualify the Range call with the correct sheet, or use
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Workbook Defined Name not available to other sheets

    Hi romperstomper;

    Now you lost me. You say first 2, but only 1 is posted.

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,309

    Re: Workbook Defined Name not available to other sheets

    It's an either or statement - either specify the sheet, or use the names collection.

+ 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