+ Reply to Thread
Results 1 to 2 of 2

How to copy worksheet with local name references

  1. #1
    Registered User
    Join Date
    07-01-2009
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    3

    How to copy worksheet with local name references

    Hi everyone,

    I have been programming vba for a couple months now and have gotten a lot of help from this forum, though there is one question which has arisen and which I can't find the answer to.

    In a new workbook I am copying a worksheet from another workbook with the usual lines

    Workbooks(filenameToCopyFrom).Sheets("Data").Copy _
    before:=Workbooks(filenameToPasteIn).Sheets(1)

    and the sheet "Data" contains many arrays with names which I would like to continue to use in the workbook "filenameToPasteIn". When I copy using the above lines, all the references of the arrays in the new workbook refer to the old workbook like:

    "='[filenameToCopyFrom.xls]Data'!$A$12:$B$5010"

    when I actually would like the names to refer to the exakt same location BUT in the new workbook's sheet "Data":

    "='[filenameToPasteIn.xls]Data'!$A$12:$B$5010" which of course could be without the filenameToPasteIn.xls in front of it..

    How can i copy while not having the names referring to the old worksheet but the new one?

    Thankful for any help!

    /Stefan

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: How to copy worksheet with local name references

    Hi Stefan

    You could either:

    1. Programmatically change links in the filenameToPasteIn.xls file to point at this file (OK, unless you have some links to the old file that you want to keep).

    or

    2. Change all the formulas to text on the sheet before you do the copy (just do a find/replace on the sheet looking for = and replacing with ###), do the sheet copy then reverse the process ie look for ### and replace with = (this will convert all the formulas back to proper formulas).

    Richard
    Richard Schollar
    Microsoft MVP - Excel

+ 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