Rename Tabs

-emma-

Board Regular
Joined
Jul 14, 2006
Messages
167
Hi,

I am using a spread sheet which contains a "CoverSheet" tab naming 6 different people. Cells A2 - A7 hold names of people. The spread sheet contains another 6 tabs each labled the same as cells A2 - A7. Unfortunatly I change the names in cells A2 - A7 on a regular basis and would like the tab names to automaticly change too.

Any ideas anyone? Any suggestions would be helpful.

Thanks,

Emma
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
Hello Emma, welcome to the board.
You can use a bit of vba for that.
Insert a standard module and put this into it.
Public OldName As String

Put this into the sheet module for CoverSheet.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then OldName = "": Exit Sub
If Not Intersect(Target, Range("A2:A7")) Is Nothing Then _
  OldName = Target.Value
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("A2:A7")) Is Nothing Then Exit Sub

If OldName <> "" And Target.Value <> OldName Then
  Dim Sheet As Worksheet
  For Each Sheet In Worksheets
    On Error GoTo ErrTrp
    If Sheet.Name = OldName Then Sheet.Name = Target.Value
  Next Sheet
End If
Exit Sub

ErrTrp:
If Err.Number = 1004 Then
  MsgBox "There is already a sheet named '" & Target.Value & "'." & Chr(10) & _
         "Please choose a name not currently being used."
  Target.Value = OldName
Else
  MsgBox Err.Number & ": " & Err.Description
End If
         
End Sub
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
You're welcome. Glad it helped.
Please check the code you have against what's posted there now as I had made
a few changes to make it a bit more robust and I don't know if you got the
latest version or the original. :wink:
 

Forum statistics

Threads
1,140,917
Messages
5,703,168
Members
421,279
Latest member
emzy

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
Top