+ Reply to Thread
Results 1 to 6 of 6

Macro to Rename Worksheet Tab with Workbook File Name

Hybrid View

  1. #1
    Registered User
    Join Date
    04-07-2009
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    12

    Macro to Rename Worksheet Tab with Workbook File Name

    Hi all - I'm looking for either a simple or more complex solution.

    Simple: I'm looking for a macro to rename the Worksheet Tab in my workbook to the filename without the ".xls".

    Complex: I have about 220 1-sheet workbooks that I need to consolidate into 22 separate workbooks with 10 worksheet tabs each.

    For example, I have 10 separate workbooks with the file names as follows: ABC-Account1.xls, ABC-Account2.xls, ABC-Account3.xls....ABC-Account10.xls. Each of these workbooks consist of just 1 worksheet, tab named "Account Definite Production by "
    I want to do the following:
    - In each individual workbook, rename the Worksheet Tab to Account1, Account2, Account3....Account10 (remove the "ABC-"and ".xls")
    - Create a NEW Workbook with the file name "ABC" and 10 worksheet tabs Account1, Account2, Account3....Account10

    Any help will be greatly appreciated!
    SP
    Last edited by sonyap; 05-21-2013 at 04:38 PM. Reason: Solved

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to Rename Worksheet Tab with Workbook File Name

    Hi Sonyap,

    Can you post a sample?
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    04-07-2009
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Macro to Rename Worksheet Tab with Workbook File Name

    Hi xladept - I attached 3 workbooks:
    - ABC.xls
    - ABC-Account1.xls
    - ABC-Account2.xls

    "ABC-Account1.xls" and "ABC-Account2.xls" are samples of the 220+ report that I currently have. "ABC.xls" is what I want to compile the existing reports into, so that I end up with 22 workbooks of 10 sheets each.

    Or, a simpler fix, is just a macro to rename the worksheet tab as the filename without the prefix "ABC-" and ".xls" so that I can select/move the sheets into a new workbook.

    Thanks for looking at this for me!!
    Attached Files Attached Files

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to Rename Worksheet Tab with Workbook File Name

    Hi Sonyap,

    Or, a simpler fix, is just a macro to rename the worksheet tab as the filename without the prefix "ABC-" and ".xls" so that I can select/move the sheets into a new workbook.
    This routine depends upon there being just one worksheet in each book!


    Sub Sonyap(): Dim wb As Workbook, ws As Worksheet, N As String, T As String
    For Each wb In Workbooks: N = wb.Name
    If Left(N, 4) = "ABC-" Then
    T = Mid(N, 5, Len(N) - 8)
    Set ws = wb.Sheets(1): ws.Name = T
    End If
    Next: End Sub
    Why not one workbook with 220 sheets??
    Last edited by xladept; 05-21-2013 at 03:42 PM.

  5. #5
    Registered User
    Join Date
    04-07-2009
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Macro to Rename Worksheet Tab with Workbook File Name

    It works! Thanks!

    And it's only 1 sheet per workbook because that's how my SSRS parameters are set up- search account name with % wildcards. It's great when I just need 1 account's production, but a pain in the A when I need to pull multiple.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to Rename Worksheet Tab with Workbook File Name

    Hi Sonyap,

    You're welcome!

    Consider using one book with the 220 sheets - you could, easily, set up a 221st sheet as an index and use a double click event to navigate between the index and the Account sheets.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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