Problem with tab names equaling cell name.

cole516gray

New Member
Joined
Dec 2, 2013
Messages
6
I found a code to make the tab name equal a cell in the worksheet:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 Const WS_RANGE As String = "ad1" '<== change to suit
 On Error GoTo ws_exit
 Application.EnableEvents = False
 If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
 With Target
 Me.Name = .Value
 End With
 End If
ws_exit:
 Application.EnableEvents = True
 End Sub

This worked great for the first worksheet, but it is not working for any of the other sheets. Can anyone tell me if I am missing something in the code?
 
Last edited by a moderator:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You're turning events off but only turning them on again if you encounter an error.

Try something along these lines:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Const WS_RANGE As String = "ad1" '<== change to suit
On Error GoTo ws_exit


Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Name = .Value
End With
End If

Application.EnableEvents = True

Exit Sub



ws_exit:
Application.EnableEvents = True
MsgBox "Sheet NOT named."

End Sub
 
Upvote 0
I am now copying the tabs and the tabs are initially being renamed, however if I change the cell name after the initial time of renaming the cell, the tab name is not adjusting accordingly. Is there a way to make it always adjust with the cell name or are there specific conditions it will work in?
 
Upvote 0
Slightly different., it doesn't rely on the name of the cell.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Tcell As Range

Set Tcell = ActiveSheet.Range("AD1")

If Target <> Tcell Then Exit Sub

On Error GoTo ws_exit

Application.EnableEvents = False
ActiveSheet.Name = Tcell
Application.EnableEvents = True

Exit Sub

ws_exit:
Application.EnableEvents = True
MsgBox "Sheet NOT named."

End Sub
 
Upvote 0
This will only work with the sheet that the code is in by the way. It won't have any effect on other sheets that do not contain the above code.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top