+ Reply to Thread
Results 1 to 3 of 3

Referring to named ranges (again)

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Referring to named ranges (again)

    I got some assistance before on referring a single named cell in some VBA code. Based on that I've now a piece of code that looks like:

    Please Login or Register  to view this content.
    Which appears to fail miserably. Method 'Range ' of object '_Worksheet' failed. This code is contained in a Worksheet_Activate event for a particular sheet. While the named range is not on that sheet it is workbook level (I can type in "+country" anywhere and get an answer).

    Is there some difference with using this code at an event level rather than in a normal moduel that I am missing?

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

    Re: Referring to named ranges (again)

    In a worksheet code module, Range refers to that worksheet unless otherwise specified. You should be able to just use Application.Range instead of Range, or use ThisWorkbook.Names("country").RefersToRange to be safe.

  3. #3
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Referring to named ranges (again)

    Worked a charm. Thanks very much.

+ 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] VBA creates named ranges, but named ranges disappear
    By BrotherNeptune in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2015, 03:22 PM
  2. Define only 2 named ranges from a list of named ranges...
    By abhi900 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-29-2014, 04:20 AM
  3. Referring to Named Ranges defined with OFFSET()
    By jaskamakkara in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-20-2013, 03:55 AM
  4. Functions referring to Named Ranges
    By taa in forum Excel General
    Replies: 2
    Last Post: 03-25-2011, 04:17 PM
  5. Referring to Named Cells in VB
    By Sam Steiner in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2007, 11:27 PM
  6. Referring to named ranges in a macro
    By Pontificateur in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-16-2005, 02:05 PM
  7. Referring to named ranges
    By Hardy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-25-2005, 08:05 AM

Tags for this Thread

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