+ Reply to Thread
Results 1 to 5 of 5

Referencing sheets after copying

  1. #1
    Forum Contributor
    Join Date
    06-15-2011
    Location
    Chester, England
    MS-Off Ver
    Excel 2013
    Posts
    117

    Referencing sheets after copying

    Excerpt from my macro:

    Please Login or Register  to view this content.
    When I use:

    Please Login or Register  to view this content.
    This applies to the sheets in the new workbook.

    When I use:

    Please Login or Register  to view this content.
    This applies to the sheets in the original workbook - why is this?

    Can I use the sheet codename to reference the relevant one in the new workbook?

    One thing I tried was:

    Please Login or Register  to view this content.
    at the relevant points, then use:

    Please Login or Register  to view this content.
    but that gave an error - what is the correct way to express this?

    Thanks in advance.
    Last edited by tone640; 09-30-2011 at 10:45 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,607

    Re: Referencing sheets after copying

    It would be best if you explained what you are trying to do. If you have more than one workbook in play you ought to add a reference to that as well as the worksheet.

  3. #3
    Forum Contributor
    Join Date
    06-15-2011
    Location
    Chester, England
    MS-Off Ver
    Excel 2013
    Posts
    117

    Re: Referencing sheets after copying

    I am trying to copy two sheets to a new workbook then enter the following:

    Please Login or Register  to view this content.
    On the new workbook, but can't understand why 'Sheet23' references the original workbook, but 'Sheets("wage and revenue") references the new one.

    And I have tried your suggestion, but as described above am unable to get the syntax right when using the codename:

    Please Login or Register  to view this content.
    works fine, but:

    Please Login or Register  to view this content.
    gives an error.
    Last edited by tone640; 09-30-2011 at 08:25 AM.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Referencing sheets after copying

    You can only use the codename when referring to a sheet in the same project (workbook) as the code, unless you set a reference to the other workbook (very difficult if you just created it at runtime).
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Contributor
    Join Date
    06-15-2011
    Location
    Chester, England
    MS-Off Ver
    Excel 2013
    Posts
    117

    Re: Referencing sheets after copying

    Got it, thank you.

+ 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