+ Reply to Thread
Results 1 to 4 of 4

Worksheet Change Event-what I expect it to do

Hybrid View

  1. #1
    Registered User
    Join Date
    12-13-2009
    Location
    new york, usa
    MS-Off Ver
    Excel 2003
    Posts
    17

    Question Worksheet Change Event-what I expect it to do

    I have the following code:

    Sub TabName()
        ActiveSheet.Name = ActiveSheet.Range("A5")
    End Sub
    The above code works fine, though I have to run the macro each time manually.

    I am trying to make it dynamic using the following code:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
       If Target.Address = "$A$5" Then
    
            ActiveSheet.Name = ActiveSheet.Range("A5")
    
       End If
    End Sub

    This code does not do what I expect it to do, which is rename the sheet if i change the text in cell A5.

    Any help would be appreciated.
    Last edited by teylyn; 05-29-2010 at 08:11 AM. Reason: added code tags

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Worksheet Change Event question

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Code tags added this time only!

    Where did you put the Worksheet_Change macro? It belongs in the Sheet module, where it will do what you describe. I've run it without any problems.
    Last edited by teylyn; 05-29-2010 at 08:11 AM.

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Worksheet Change Event question

    Ooops to late. Sorry Teylyn

    Please wrap your code in code tags, before the moderators get you...

    Forum rules
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button.
    Then try
    Private Sub Worksheet_Change(ByVal Target As Range)
        Target = Trim(Target)
        If Target = "" Then Exit Sub
        If Target.Address = "$A$5" Then
            Sheet1.Name = Target
        End If
    End Sub
    Remember because the SheetName changes you have to refer to Sheet1, Sheet2, etc
    Also this will not allow the sheet name to be "", or a string of spaces.

    Hope this helps

  4. #4
    Registered User
    Join Date
    12-13-2009
    Location
    new york, usa
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Worksheet Change Event question

    Thank you,

    I did not have the code in the sheet module ... that was it. Solved.

+ 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