Is it possible to have the tab named as the same as what I enter in A1?
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.
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
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
in the work sheet module not a new module it doesn't show in the macros it runs when a1 is changed
Ok thanks, I have got that bit to work now.
But i am getting the following error?
ooh arr err it did work then stopped i must have missed something in the code ill see if someone else can fix it!
You are missingbefore you try to refer to the worksheet which may not exist.On Error Resume Next
Remember what the dormouse said
Feed your head
Try this
Place the Function in a standard moduleOption 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
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
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
Thank you that has worked
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
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks