+ Reply to Thread
Results 1 to 7 of 7

VBA code for copying a worksheet and pasting it as a new worksheet in Excel

  1. #1
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    VBA code for copying a worksheet and pasting it as a new worksheet in Excel

    I am playing with recording a macro to select an entire worksheet, copy and paste it in a new worksheet, same excel workbook, and pasting it there. I figured out the following code for doing so:

    Please Login or Register  to view this content.
    What I like about this is the next worksheet is named "Candidate (2)" and the next "Candidate (3)" and so on. This clarifies perfectly for the user.

    1) What I don't like about this is worksheet Candidate (3) is between Candidate (1) and Candidate (2) because I've specified to put it after the first worksheet. I've tried to change the code to read before another specific sheet, but It didn't want to cooperate. I have a worksheet in my workbook for Values. In the Microsoft Excel Objects list it's listed as Sheet3 (Values). How do I have it place it before that always? That should always keep the numbering in order (Unless there is a better way to do this).

    2) On my UserForm, is there a way for me to provide the user with a field to enter the number of times this should repeat, or loop (I assume this would be an example of a time when looping would occur).

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA code for copying a worksheet and pasting it as a new worksheet in Excel

    If the new sheets to be created should be placed at the end of your list of sheets, you can try -
    Please Login or Register  to view this content.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: VBA code for copying a worksheet and pasting it as a new worksheet in Excel

    That did work beautifully, thank you. If I could have it always before the sheet "values" that would be even better. The above code always places the sheets in order, as preferred, but after values.

  4. #4
    Registered User
    Join Date
    06-17-2009
    Location
    Canada
    MS-Off Ver
    Office 2010
    Posts
    84

    Re: VBA code for copying a worksheet and pasting it as a new worksheet in Excel

    Trying adding this.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: VBA code for copying a worksheet and pasting it as a new worksheet in Excel

    Thank you.

    For some reason, it didn't like this line:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-17-2009
    Location
    Canada
    MS-Off Ver
    Office 2010
    Posts
    84

    Re: VBA code for copying a worksheet and pasting it as a new worksheet in Excel

    It looks like this code does not work on version 2003 or earlier. I will try some changes late today. I used 2007 and it works.
    I tested on 2003 and it does not.

  7. #7
    Forum Contributor
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    292

    Re: VBA code for copying a worksheet and pasting it as a new worksheet in Excel

    Wait! Before you do that.... We upgraded to 2010 last week!! Though, some people in my office may still use 2003, it is unlikely that will last long.

+ 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