+ Reply to Thread
Results 1 to 15 of 15

Name a Worksheet Based on a Value in a Cell

Hybrid View

  1. #1
    Registered User
    Join Date
    06-14-2010
    Location
    United States
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    18

    Name a Worksheet Based on a Value in a Cell

    I have a workbook containing 25 worksheets. i would like for each worksheet to be named based on what is in cell S6. Does anyone know how I can do this? I might add that S6 has a vlookup in it that pulls in its value....Please help. Thanks!

  2. #2
    Registered User
    Join Date
    06-03-2013
    Location
    Earth
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Name a Worksheet Based on a Value in a Cell

    I do it this way in one of my projects
    Normally I do this from a form, but this should work.

    Just reread your post, you would have to loop through each sheet and look at the same cell location.


    Set ws = Worksheets("Schedule")
    
    sName= ws.Cells(iRow, 1)
    
    ActiveSheet.Name = sName
    Last edited by RobWulf; 06-24-2014 at 12:19 PM.

  3. #3
    Registered User
    Join Date
    06-14-2010
    Location
    United States
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    18

    Re: Name a Worksheet Based on a Value in a Cell

    Im not really sure what you mean that I need to do...sorry, I am not very good at this stuff...

    Jo

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Name a Worksheet Based on a Value in a Cell

    Maybe:

    Sub bridgeport()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        ws.Activate
        ActiveSheet.Name = Range("S6").Value
    Next ws
    End Sub

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Name a Worksheet Based on a Value in a Cell

    Hi,

    What RobWulf is saying is that unless you do it manually you will need a macro to do it for you. Are you familiar with macro code and where it sits.

    Perhaps the basic question is are the sheet names going to be changing continually when S6 changes? If not I'd be inclined to bite the bullet and just rename them manually. That will be quicker than implementing a macro if you're not yet familiar with them.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  6. #6
    Registered User
    Join Date
    06-14-2010
    Location
    United States
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    18

    Re: Name a Worksheet Based on a Value in a Cell

    Yes, the value in S6 is always going to change....this is going to be used for approx. 600 worksheets all together. i think I need to create a macro, but need guidance as to how to do it....can you help?

  7. #7
    Registered User
    Join Date
    06-14-2010
    Location
    United States
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    18

    Re: Name a Worksheet Based on a Value in a Cell

    The below sentence hilighted when i ran this....So you know what I might have done wrong?

    Thanks! Jo

    ActiveSheet.Name = Range("S6").Value

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Name a Worksheet Based on a Value in a Cell

    Can you post the code you ran? I tested my suggestion and it worked for me.

  9. #9
    Registered User
    Join Date
    06-14-2010
    Location
    United States
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    18

    Re: Name a Worksheet Based on a Value in a Cell

    Can I email you the file? don't really fee comfortable posting it..??

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Name a Worksheet Based on a Value in a Cell

    I only want to look at the code. Only to check that it is the same as I posted and what may be causing the error. I don't think there would be any confidentiallity involved there? Not sure.

  11. #11
    Registered User
    Join Date
    06-14-2010
    Location
    United States
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    18

    Re: Name a Worksheet Based on a Value in a Cell

    When I put the below code in , I get a Microsoft Visual Basic box pop up that says

    Run-time error '1004':
    Application-defined or object-defined error, then I have the option to end, debug, or help.

    Sub bridgeport()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    ws.Activate
    ActiveSheet.Name = Range("S6").Value
    Next ws
    End Sub

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Name a Worksheet Based on a Value in a Cell

    Try:

    Sub bridgeport()
    Dim ws As Worksheet
    On Error Resume Next
    For Each ws In ActiveWorkbook.Worksheets
        ws.Activate
        ActiveSheet.Name = ws.Range("S6").Value
    Next ws
    On Error GoTo 0
    End Sub

  13. #13
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Name a Worksheet Based on a Value in a Cell

    You have to use tags (#) on your code.

    I think you don't have a value in S6.

    This could cause the trouble.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  14. #14
    Registered User
    Join Date
    06-14-2010
    Location
    United States
    MS-Off Ver
    Microsoft Excel 2007
    Posts
    18

    Re: Name a Worksheet Based on a Value in a Cell

    Okay, so this is working on all but the last two sheets in the workbook...do you know what I could be doing wrong? Please help....we are sooo close!! Thanks!

  15. #15
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Name a Worksheet Based on a Value in a Cell

    Maybe you could reply on the answer in #12.

+ 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. Macro to hide rows on a worksheet, based on a cell's value on another worksheet.
    By buttercup116 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-29-2014, 10:47 AM
  2. Copy data from a copied worksheet to another worksheet based on cell reference
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2013, 02:18 PM
  3. Macro to select worksheet based on cell value and then return data to diff worksheet
    By clnossok in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2013, 07:48 PM
  4. Replies: 4
    Last Post: 10-30-2012, 06:15 PM
  5. [SOLVED] Copy rows from my main worksheet to another worksheet based on data in one cell
    By gcol in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-08-2012, 05:12 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