Private Sub Worksheet_Change(ByVal Target As Range)
'autoname the worksheet Tab from value in A1
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
On Error GoTo CleanUp
Application.EnableEvents = False
With Target
If .Value <> "" Then
Me.Name = .Value
End If
End With
CleanUp:
Application.EnableEvents = True
End Sub
Right-click on the sheet tab and "View Code". Copy/paste the code into that
module.
Use the code I posted but change it slightly to make it run on all sheets.
Remove the code from the sheet module and place this revision into
Thisworkbook module.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
'autoname the worksheet Tab from value in B9
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("B9")) Is Nothing Then Exit Sub
On Error GoTo CleanUp
Application.EnableEvents = False
With Target
If .Value <> "" Then
Me.Name = .Value
End If
End With
CleanUp:
Application.EnableEvents = True
End Sub
Gord, how do I run this sub? When I put it in the ThisWorkbook module it
doesn't show up in the Maacro list - I would like to have a shortcut key to
run it.
It is event code, not a macro to be run via a button or shortcut key.
The code runs on any sheet when you change the value in B9 manually.
If you want a macro to run from a shortcut key use the rNmae macro the other
responder posted.
Gord
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.