+ Reply to Thread
Results 1 to 6 of 6

VBA to Copy Sheet and Rename, with Sheetname used in Macro

  1. #1
    Registered User
    Join Date
    03-11-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    VBA to Copy Sheet and Rename, with Sheetname used in Macro

    Hi Guys,

    So in my workbook, I need to be able to copy the first sheet exactly, but rename it with whatever the user wants, for which I've used this:

    Please Login or Register  to view this content.
    The trouble I'm having is that the Macro within the sheet I need to copy has a sheet reference, using the name of the first sheet, rather than an ActiveSheet type reference, like this:

    Please Login or Register  to view this content.
    So when I copy the sheet across, and run the macro, it runs it in the first sheet, instead of the new sheet.


    Firstly, is there a more elegant way to copy the sheet?
    And secondly, is there a way to get the macro to work on the new sheet, rather than the original?

    Thanks,
    Mike

  2. #2
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: VBA to Copy Sheet and Rename, with Sheetname used in Macro

    Mike

    Can you upload a copy of the workbook so we can see exactly what the on-sheet macro is trying to do.
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  3. #3
    Registered User
    Join Date
    03-11-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: VBA to Copy Sheet and Rename, with Sheetname used in Macro

    Sure, here's the workbook.

    Any improvement ideas would be welcome!
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-11-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: VBA to Copy Sheet and Rename, with Sheetname used in Macro

    Bump, still looking for a solution.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA to Copy Sheet and Rename, with Sheetname used in Macro

    Your request is not clear

    Do not use Worksheets(1).
    use either code name for the sheet , or refer it by its sheet name like sheets("Sheet1")
    I used Me as a worksheet and creates sheet me.

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: VBA to Copy Sheet and Rename, with Sheetname used in Macro

    Hi Mike

    Change your code as follows

    Please Login or Register  to view this content.
    and for Addin Employee rows, you can simplify to
    Please Login or Register  to view this content.
    Note that I moved your word TOTALS to column B on the sheet instead of column A.
    This allows you to use count up to find the last row, rather than looping.
    Attached Files Attached Files

+ 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. Replies: 4
    Last Post: 08-16-2013, 04:10 AM
  2. Macro open files and copy sheet and rename sheet
    By matrix_xrs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2013, 04:33 AM
  3. Macro - Copy sheet and rename based on cell value
    By Nick.123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2013, 04:23 AM
  4. Macro for Copy Sheet+Rename
    By C3Sound in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2010, 04:56 PM
  5. [SOLVED] Run Macro & Rename Sheet upon creating copy from blank.
    By Kervin Manasseh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-14-2005, 07:05 AM

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