Tab Name

mrs Doyle

New Member
Joined
May 30, 2002
Messages
20
I am sure I saw the answer to this the other month but I can't find it at the moment.

I want the tab name to be picked up from the spreadsheet.
EG if I type "ASSETS" in cell A1 I would like the tab name to pick it up

hope this makes sense
thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You need to use a worksheet Change event macro to do this. Right-click on the sheet tab, choose View Code and copy and paste in the code below. The error trap is there in case you type in an illegal name or try to rename as an existing worksheet:-

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

With Target
    If .Count = 1 Then
        If .Address = "$A$1" Then
            On Error Resume Next
            Me.Name = .Value
        End If
    End If
    If Err Then MsgBox "Unable to rename worksheet as " & .Value
    On Error GoTo 0
End With

End Sub
 
Upvote 0
Hi Mudface

I used your code and it works a treat.

How can I modify it to work on each sheet in the workbook
 
Upvote 0
Instead of placing the code in the worksheet module, place this in the ThisWorkbook module: -

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Excel.Range)

With Target
    If .Count = 1 Then
        If .Address = "$A$1" Then
            On Error Resume Next
            Sh.Name = .Value
        End If
    End If
    If Err Then MsgBox "Unable to rename worksheet as " & .Value
    On Error GoTo 0
End With

End Sub
 
Upvote 0
Most excellent Mudface. Again works beautifully. Many thanks.

Apologies to mrs Doyle for butting in.
 
Upvote 0
Can you tell me what is the reason for the line "Me.Name = .Value " in the code for a worksheet, in comparison with "Sh.Name = .Value " for that for the workbook?
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,336
Members
451,697
Latest member
pedroDH

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