+ Reply to Thread
Results 1 to 10 of 10

Naming a worksheet from a cell in another worksheet

  1. #1
    Registered User
    Join Date
    03-11-2008
    Posts
    34

    Naming a worksheet from a cell in another worksheet

    Is it possible to name a worksheet by entering the name in a cell from another worksheet in the same workbook? I am building a macro and am missing this crucial step.

    I would like it so that someone else could come along and change the name in the cell and the name of the workbook would change too.

    Below is the code so far:
    Please Login or Register  to view this content.
    Thanks.
    Last edited by NBVC; 05-20-2008 at 08:51 AM.

  2. #2
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hi sportsranker,

    Quick solution is....

    If you named ythe cell that you wanted to use to set the sheet name to "Name" or something relivent and then where you want the sheet name to change just add the following piece of code

    Please Login or Register  to view this content.
    or somthing similer to that.

  3. #3
    Registered User
    Join Date
    03-11-2008
    Posts
    34
    Stuie, thanks for the help.

    Just to clarify:

    If the cell is N46 on the "Controls" workbook, then the proper code would be:

    Sheets("Controls").Select
    Sheets("Template (2)").Name = Range("N46").Value

    I seem to get an error when I run this.

  4. #4
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Is there error telling something about naming it with no name or something, the Sheets("Template (2)").Name = Range("N46").Value part is telling it to use the value in range("N46") on the control sheet as you have selected that sheet to be active, so try adding
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-11-2008
    Posts
    34
    The original error went away without using the second adjustment (strangely enough).

    The first line of code you mentioned works now. But if I change the text in the cell, the name of the worksheet does not change with it. Is this even possible?

    Thanks.

  6. #6
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    It will only change when the macro is ran,

    If you want it change when the N46 is changed you will need to tap into the Worksheet_Changed event try pasting this into the worksheet where the range with the name is used

    Please Login or Register  to view this content.
    EDIT: its ment to be If Target.Address = "$N$46" Then
    and reference the sheet number not sheet name as the name will change

    so should look like
    Please Login or Register  to view this content.
    Last edited by Stuie; 05-20-2008 at 09:51 AM.

  7. #7
    Registered User
    Join Date
    03-11-2008
    Posts
    34
    I am a little confused as to where I need to paste that code into the N46 on the controls worksheet?

  8. #8
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Sorry, i didnt explain it very well now i have read it back,

    The sheet where you enter the name in cell n46 needs the code entered into its sheets events, in the vba editor if you look on the Projects window it shoud say for example Sheet1 ("Sheet1")

    Find the sheet you need and double click it, that will bring up a window where you will be able to paste the code into

  9. #9
    Registered User
    Join Date
    03-11-2008
    Posts
    34
    Thanks Stuie. I can take it from here.

  10. #10
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Cool no probs, any futher questions give me a shout

+ 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