+ Reply to Thread
Results 1 to 4 of 4

automating renaming a worksheet tab, where the worksheet tab is dynamic

  1. #1
    Registered User
    Join Date
    07-07-2015
    Location
    Wash DC
    MS-Off Ver
    10
    Posts
    57

    automating renaming a worksheet tab, where the worksheet tab is dynamic

    Help

    I inherited a excel macro that needs to be changed, and I am at a loss..

    The way the script works is that is automatically imports a series of .csv files as individual worksheet tabs which works great.. The issue is that there is a master worksheet that isn't imported that pulls in data from these tabs to calculate specific data...

    The problems is that the files used to be static, but now as the data has increased they names are a dynamic

    The files used to be named

    IEP_Batch1_GETS_GenericReport thru IEP_Batch8_GETS_GenericReport

    However the files are now named via the different servers that produce the data..

    The files are now named

    8X_IEP_BatchXX_GETS_GenericReport

    where the 8X can be 80 thru 86
    and BatchXX can be Batch1a and Batch1b thru Batch8a and Batch8b (batch names are split now between only a/b only not the whole alphabet)

    THe only way that actually works is to do a "on error resume next" then to try and select the files If it exists and then rename it ...

    like this .

    Sheets("80_IEP_Batch1a_GETS_GenericReport").Select
    Sheets("80_IEP_Batch1a_GETS_GenericReport").Name = "Batch1a_GETS"
    Sheets("81_IEP_Batch1a_GETS_GenericReport").Select
    Sheets("81_IEP_Batch1a_GETS_GenericReport").Name = "Batch1a_GETS"
    Sheets("82_IEP_Batch1a_GETS_GenericReport").Select
    Sheets("82_IEP_Batch1a_GETS_GenericReport").Name = "Batch1a_GETS"
    Sheets("83_IEP_Batch1a_GETS_GenericReport").Select
    Sheets("83_IEP_Batch1a_GETS_GenericReport").Name = "Batch1a_GETS"
    Sheets("84_IEP_Batch1a_GETS_GenericReport").Select
    Sheets("84_IEP_Batch1a_GETS_GenericReport").Name = "Batch1a_GETS"
    Sheets("85_IEP_Batch1a_GETS_GenericReport").Select
    Sheets("85_IEP_Batch1a_GETS_GenericReport").Name = "Batch1a_GETS"
    Sheets("86_IEP_Batch1a_GETS_GenericReport").Select
    Sheets("86_IEP_Batch1a_GETS_GenericReport").Name = "Batch1a_GETS"

    The problem is that for I have to duplicate this code multiple times (16 times - a/b for 1-8) ... As I will need Batch1a and Batch1b thru Batch8a and Batch8b

    Ive tried doing a loops
    Dim i As Long, strTabName As String
    but for the life of me I can't get it to work... Even if I could get part done a/b I could loop it a 2nd time for 1-8, but nada...

    what I have works - but its kludgy.... and help to take it to less step would be appreciated...

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: automating renaming a worksheet tab, where the worksheet tab is dynamic

    I think this should do it.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    07-07-2015
    Location
    Wash DC
    MS-Off Ver
    10
    Posts
    57

    Re: automating renaming a worksheet tab, where the worksheet tab is dynamic

    will try tonight ... thanks

    curious to what

    For ab = 97 To 98

    is for...

    I can understand some of it, but that has me going .... hmmmmm

  4. #4
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: automating renaming a worksheet tab, where the worksheet tab is dynamic

    the 97 to 98 loop is the loop controlling a and b (ASCII char 97 = lowercase a and 98 is lowercase b) the "chr(ab)" in the setting of tmpSheet converts the value to the character.

+ 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. Help with renaming worksheet
    By pooky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2015, 10:31 PM
  2. Dynamic drop down + fields and auto populate from one worksheet to another worksheet
    By Shermaine2010 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-26-2014, 04:57 AM
  3. Automating Worksheet Name
    By Olapop in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-29-2013, 01:44 PM
  4. Replies: 11
    Last Post: 12-06-2012, 01:48 PM
  5. Renaming a worksheet which is obtained everyday and has a dynamic naming convention
    By Abhushan86 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2012, 06:08 AM
  6. Copy dynamic data from worksheet to another identifying by the name of worksheet
    By c.wang in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-20-2009, 08:05 PM
  7. Worksheet Renaming
    By JSS in forum Excel General
    Replies: 6
    Last Post: 04-17-2006, 08:28 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