+ Reply to Thread
Results 1 to 13 of 13

Thread: Sheet Tab Names

  1. #1
    Registered User
    Join Date
    11-14-2003
    Posts
    5

    Sheet Tab Names

    I have numerous Sheets which are named using dates from 01.12.09 right through to 30.11.10. The 1st sheet has a cell in B1 containing the date and that sheet is named after the inputted date. This applies to all the other sheets which are calculated from what is input in the 1st sheet and each individual sheet is renamed manually to coincide with the inputted date. Each sheet is identical in format.

    Is it possible to have the Sheet names automatically named when the 1st date on the 1st sheet is input? I ask as I have to update the sheet each year and renaming each tab is a chore!!

  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    768

    Re: Sheet Tab Names

    This code renames all the sheets in one go

    Code:
    Sub RenameSheets()
        Dim rng As Range
        Dim wks As Worksheet
        
        For Each wks In ThisWorkbook.Worksheets()
            Set rng = wks.Range("A1")     'change this to the cell that contains the value
            wks.Name = Format(rng, "dd.mm.yy")   'change this for the actual format you want
        Next
        MsgBox "Done"
    End Sub


    Hope this was useful or entertaining.

  3. #3
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    768

    Re: Sheet Tab Names

    Just realised that you said cell B1 ... this code is corrected

    Quote Originally Posted by tony h View Post
    This code renames all the sheets in one go

    Code:
    Sub RenameSheets()
        Dim rng As Range
        Dim wks As Worksheet
        
        For Each wks In ThisWorkbook.Worksheets()
            Set rng = wks.Range("B1")     'change this to the cell that contains the value
            wks.Name = Format(rng, "dd.mm.yy")   'change this for the actual format you want
        Next
        MsgBox "Done"
    End Sub


    Hope this was useful or entertaining.

  4. #4
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,444

    Re: Sheet Tab Names

    What sort of data are you storing. If it can be placed into a table Format - one row for each day, then use VLOOKUP to populate a sheet for viewing it would be much easier to manage.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  5. #5
    Registered User
    Join Date
    11-14-2003
    Posts
    5

    Re: Sheet Tab Names

    Thanks Tony.
    Only ever put a few lines of code in before and that was in Excel 2004 using VB editor. I'm now using Excel 2008 and don't know where to put it. Sorry!
    Oh and I use the Mac version.
    Last edited by wella; 03-18-2010 at 12:34 PM. Reason: Mac user

  6. #6
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    768

    Re: Sheet Tab Names

    FIRST MAKE A COPY OF YOUR SPREADSHEET just in case

    Then:
    To get to the code section from a normal worksheet:
    - click on the "Developer" tab
    - click on "view code"

    This will bring up the code section

    - click on "insert" ... "module"

    - in the main part of the screen just under "(general)" paste in the code from this post

    Now the code is in your workbook
    - click on the line "Sub RenameSheets()" in fact any of the lines below will do just as well.
    - press F5 - this will cause the macro to run

    Let us know how you get on ... there are some reasons why the code might not run but it will be easier if you say what happens than if I try and list every possible problem.


    I think this youtube is for Excel on the mac. It might give you a sense of the VBA screens.I haven't looked at it properly.
    http://www.youtube.com/watch?v=nDsAwG87Wa0



    Hope this was useful or entertaining.

  7. #7
    Registered User
    Join Date
    01-28-2008
    Posts
    54

    Re: Sheet Tab Names

    If you are unfamiliar with VBA, this might be easier to read. It works. It's the same idea as originally posted with fewer abbreviations.
    Sub RenameSheets()
    For Each Worksheet In Sheets
    MyDate = Worksheet.Range("A1").Value 'change this to the cell that contains the value
    Worksheet.Name = Format(MyDate, "dd mm yy") 'change this for the actual format you want
    Next Worksheet
    End Sub

  8. #8
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Sheet Tab Names

    Larry, please edit your post to add code tags.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    768

    Re: Sheet Tab Names

    Dear Wella,

    I suggest you follow my original. Proper variable declaration (they are not abbreviations) makes for more robust code. By all means use longer variable names but do declare them. And my advice is don't use a name that is a class property or method.

    It is also good practice (in the Code window) to go to Tools. Options and ensure that "require variable declaration" is ticked, This puts the line "Option Explicit" at the top of each module.



    Hope this was useful or entertaining.

  10. #10
    Registered User
    Join Date
    11-14-2003
    Posts
    5

    Re: Sheet Tab Names

    Tony, i've searched for the developer tab everywhere but to no avail. Apparently VB is no longer used in Excel 2008 Mac version and has been replaced by Applescript which leaves me in the wilderness!!

    Excuse my ignorance but although I understand a little coding I haven't delved into it very much. Maybe i'm looking in the wrong place and hopefully you can shed some light on it to resolve the issue.

    Thanks in advance.

  11. #11
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Sheet Tab Names

    There is indeed no VBA in Excel 2008.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  12. #12
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    768

    Re: Sheet Tab Names

    Quote Originally Posted by wella View Post
    Tony, i've searched for the developer tab everywhere but to no avail. Apparently VB is no longer used in Excel 2008 Mac version and has been replaced by Applescript which leaves me in the wilderness!!

    Excuse my ignorance but although I understand a little coding I haven't delved into it very much. Maybe i'm looking in the wrong place and hopefully you can shed some light on it to resolve the issue.

    Thanks in advance.
    A Mac That leaves me in the wilderness.

    If shg says "There is indeed no VBA in Excel 2008" on the MAC I would assume he knows. I have no idea if Applescript has access to the object model.

    Maybe use a friend's PC to run the code; but I have no useful experience of transferring between Mac and PC.



    Hope this was useful or entertaining.

  13. #13
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,444

    Re: Sheet Tab Names

    Mac's no longer have VBA,so you can't transfer
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

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.2.0