+ Reply to Thread
Results 1 to 2 of 2

copy worksheet and name it's tab at the same time

  1. #1
    Registered User
    Join Date
    04-02-2011
    Location
    Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    38

    copy worksheet and name it's tab at the same time

    Hi,

    I'm looking to speed up an operation that is taking awhile because of the number of times it needs to loop. I need to separate about 5000 lines of data into about 100 individual tabs.

    I'm currently doing this to prepare my sheets for the data:
    Please Login or Register  to view this content.
    DSC and Tplt100 are code names. I want to copy (and not "add") because I want the new code names to start at Tplt101 and go up from there automatically, so when I'm moving the data around I can do it in a for loop down the lines of data, and move through the sheets one at a time by the code name, starting with Tplt101.

    The tab names are named from data taken from all the source data.

    The sheet it is copying is empty; I only have it there to start the code names where I want them to start. The above method works great, but it takes twice as long as this method:

    Please Login or Register  to view this content.
    The only problem with this is the code names default to the next standard code name; say at a given time it wants to start at Sheet13, and then go up from there.


    What I'd like is to combine the speed of the the sheets.add.name, but copy my specific sheet instead of adding a blank one.

    I tried this and it didn't work:
    Please Login or Register  to view this content.
    The error I get is:

    "Compile error, expected function or variable"



    I'm open to other ideas to achieve the speed, such as setting the code name programatically along with Sheets.add, but I don't know if that is possible.

    I do know how to change the code name programatically:
    Please Login or Register  to view this content.
    But that requires knowing the old code name (can I read the code name of ActiveSheet into a variable?)

    This code changes the code name via Sheet index (by variable), which is doable for me:
    Please Login or Register  to view this content.
    But it's too messy because when it copies the old codename + 1, it has a predictable index number, but then when you change the code name the index changes, and the next sheet you copy doesn't have as predictable of a index number.



    So this probably won't work, and I've also started to realize this might not be worth the trouble.

    BUT--I am still open to ideas if anyone knows how to do this efficiently. Such as; change the code name using the Tab name as the reference of what you are changing. I don't know how to do that...

  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: copy worksheet and name it's tab at the same time

    If i understood your question correctly, you need to separate 5k lines of data into 100 tabs. What has the code names to do with the separation? Maybe you can attach a sample workbook so we can understand better.
    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]

+ 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