+ Reply to Thread
Results 1 to 12 of 12

import Named Ranges?

  1. #1
    Registered User
    Join Date
    12-15-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    15

    Question import Named Ranges?

    Hi,

    I am importing an external Sheet into my Excel workbook but it only imports the data not the named ranges. I need the named ranges to be imported and overwrite any existing range of same name.

    Example:

    In existing workbook Sheet I have a named range, ABC which is A1:E10 - in the Sheet I am importing the ABC range is A1:E12. So when I have done import I want named range ABC in my workbook to become A1:E12 (as per external Sheet).

    This is the code that import data (but not named ranges)

    Please Login or Register  to view this content.
    What do I need to code? Help!

    cheers

  2. #2
    Valued Forum Contributor
    Join Date
    08-23-2009
    Location
    Hampshire, UK
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    328

    re: import Named Ranges?

    If you copy in the whole sheet instead of just the cells, it will keep the named ranges.

    Try this
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-15-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    15

    re: import Named Ranges?

    The Named Ranges are only visible within the new worksheet - they are not visible from any other sheets unlike the pre-existing Named Ranges that were global. Can this be resolved?

    Originally I wanted it to load into existing worksheet - where I have an activeX button - but I can work around that by coding it to delete existing sheet and place invoke button in different sheet.

  4. #4
    Valued Forum Contributor
    Join Date
    08-23-2009
    Location
    Hampshire, UK
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    328

    re: import Named Ranges?

    The Named Ranges are visible from all sheets in the workbook when I've tried it. Have you checked that you don't already have that name with an invalid reference from a previous attempt?

  5. #5
    Registered User
    Join Date
    12-15-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    15

    re: import Named Ranges?

    I have deleted the old sheet (which contained same named ranges) - then ran your code but the named ranges are only local to that new sheet.

    BTW I am using Excel 2007
    Last edited by Kop99; 12-29-2009 at 02:26 PM.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    re: import Named Ranges?

    If you copy a worksheet with named ranges that have workbook scope, then the new sheet will have the same ranges with sheet scope.

    You can't have two ranges by the same name that have workbook scope -- that makes sense, right?

    You can reference a named range on another sheet by prepending the sheet name, e.g., =Sheet2!Bob
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Valued Forum Contributor
    Join Date
    08-23-2009
    Location
    Hampshire, UK
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    328

    re: import Named Ranges?

    If you look in Insert - Name - Define - .... is there a copy of the name from the deleted sheet? It will have a #ref! in the "refers to" box. If there is, you'll need to delete it.

  8. #8
    Registered User
    Join Date
    12-15-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    15

    re: import Named Ranges?

    When I delete the Named Ranges (vba) - then import from external Sheet they are visible under Define but they point at the external Sheet.

    When I do not Delete the Named Ranges - they exist twice, first locally, then the global value is #REF (and not visible in other Sheets).

    Either way I have a problem.

    This is the code with the deletes in place.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    re: import Named Ranges?

    Maybe post an ad-hoc (and simple) example of wht you're trying to do, and what's broken.

  10. #10
    Registered User
    Join Date
    12-15-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    15

    re: import Named Ranges?

    I have deleted Named Ranges by VBA and also through the Name Manager GUI - in both cases the same Named Ranges from the External Sheet (after copy) refers to the External sheet itself, i.e. Value = #REF!

    I also added a new Named Range to the External Sheet and that was copied in successfully, i.e. referring to itself locally.. and visible globally to other sheets within workbook. So it sounds like to me that there is something not right with the Delete process (whether by VBA or front end of Name Manager) as if it did not previously exist not a problem.

  11. #11
    Valued Forum Contributor
    Join Date
    08-23-2009
    Location
    Hampshire, UK
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    328

    re: import Named Ranges?

    The code
    Please Login or Register  to view this content.
    will only delete workbook ranges ie those that are visible on all sheets. Is it possible that you also have a range with the same name on another sheet? You could delete it with something like
    Please Login or Register  to view this content.
    I haven't been able to replicate your problem so if this doesn't work it would really be best if you could upload sample files, as shg suggested.

  12. #12
    Registered User
    Join Date
    12-15-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: import Named Ranges?

    Have written solution for my OP, i.e. correctly updating Named Range

    ...
    ws.Range("A1").PasteSpecial
    Resize("ABC")

    Please Login or Register  to view this content.

+ 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