+ Reply to Thread
Results 1 to 12 of 12

Tab named the same as a cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-06-2011
    Location
    manchester england
    MS-Off Ver
    Office 365
    Posts
    283

    Tab named the same as a cell

    Is it possible to have the tab named as the same as what I enter in A1?
    Last edited by gjjh25; 11-15-2011 at 11:20 AM.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Tab named the same as a cell

    you can with code try this in the worksheet module for each sheet you need
    (code shamelessly cribbed and modified from somewhere else that escapes me)
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim shtchk As String
    shtchk = Range("a1").Value
    If Len(shtchk) = 0 Then Exit Sub
    If Not ThisWorkbook.Sheets(UCase(shtchk)) Is Nothing Then
    Select Case True
    Case Err.Number = 0
    MsgBox "name in use try again"
    Range("a1") = ""
    Exit Sub
    Case Err.Number <> 0
    On Error GoTo 0
    Err.Clear
    
    active.Worksheet.Name = shtchk
    
    End Select
    End If
    End Sub
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Contributor
    Join Date
    09-06-2011
    Location
    manchester england
    MS-Off Ver
    Office 365
    Posts
    283

    Re: Tab named the same as a cell

    Thanks I have copied this to a module, but when I close it and look for macros for the sheet, there are none shown?

    Am I doing something wrong?

    I am inserting a module into sheet 1 and it shows up as a module, I then close this and go back to the sheet.

    Regards

    Graham

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Tab named the same as a cell

    in the work sheet module not a new module it doesn't show in the macros it runs when a1 is changed
    Attached Images Attached Images

  5. #5
    Forum Contributor
    Join Date
    09-06-2011
    Location
    manchester england
    MS-Off Ver
    Office 365
    Posts
    283

    Re: Tab named the same as a cell

    Ok thanks, I have got that bit to work now.

    But i am getting the following error?
    Attached Images Attached Images

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Tab named the same as a cell

    ooh arr err it did work then stopped i must have missed something in the code ill see if someone else can fix it!

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Tab named the same as a cell

    You are missing
    On Error Resume Next
    before you try to refer to the worksheet which may not exist.
    Remember what the dormouse said
    Feed your head

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Tab named the same as a cell

    Try this
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim shtchk As String
    If Target.Address <> "$A$1" Then Exit Sub
    shtchk = Target.Text
    If Len(shtchk) = 0 Then Exit Sub
    If Not WksExists(shtchk) Then
    ActiveSheet.Name = shtchk
    End If
    End Sub
    
    Function WksExists(wksName As String) As Boolean
        On Error Resume Next
        WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
    End Function
    Place the Function in a standard module
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Tab named the same as a cell

    Private Sub Worksheet_Change(ByVal Target As Range)
     If Target.Address = "$A$1" And Target <> "" Then
      On Error Resume Next
      If Not Evaluate("isref(" & Target & "!A1)") Then Name = Target
      If Err.Number <> 0 Then MsgBox "A1 contains invalid characters"
     End If
    End Sub



  10. #10
    Forum Contributor
    Join Date
    09-06-2011
    Location
    manchester england
    MS-Off Ver
    Office 365
    Posts
    283

    Re: Tab named the same as a cell

    Thank you that has worked

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Tab named the same as a cell

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  12. #12
    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: Tab named the same as a cell

    Possibly this in the Workbook Module?
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
        Dim n As Long
        Dim arrIllegal As Variant
        
        If Target.Address(0, 0) = "A1" Then Exit Sub
        
        If Target <> "" Then
            If Len(Target) > 31 Then
                MsgBox "Sheet name cannot exceed 31 character - try again", vbCritical
                Target = ""
                Exit Sub
            End If
            arrIllegal = Array("/", "\", "?", ":", "*", "[", "]")
            For n = LBound(arrIllegal) To UBound(arrIllegal)
                If InStr(Target, arrIllegal(n)) > 0 Then
                    MsgBox "Illegal character in new name - try again" & Chr(13) & Chr(13) & "Illegal character:= / \ ? : * [ ] ", vbCritical
                    Target = ""
                    Exit Sub
                End If
            Next
            For n = 1 To Sheets.Count
                If UCase(Sheets(n).Name) = UCase(Target) Then
                    MsgBox "Name in use - try again", vbCritical
                    Target = ""
                    Exit Sub
                End If
            Next
            Sh.Name = Target
        End If
    End Sub
    Last edited by Marcol; 11-15-2011 at 11:33 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

+ 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