Renaming Tab Based on Cell

lapta301

Well-known Member
Joined
Nov 12, 2004
Messages
1,001
Office Version
  1. 365
Platform
  1. Windows
Dear All

I'm sorry to ask this as I have found similar questions on the board but they don't seem to work for me for some reason.

Basically I just need the worksheet tab to be renamed based on the date value in cell B2.

Short and sweet.

Many thanks


lapta301
 

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
Code:
Sub MySheetRenameByCell()
'========================================================================
' THIS WILL RENAME THE SHEET TO A CELL VALUE
' CAN GO INTO A MODULE BUT DOES NOT RUN AUTOMATICALLY
'========================================================================
    On Error Resume Next
ActiveSheet.Name = Range("B2").Value
End Sub
 
Upvote 0
Code:
Sub NameSheets()
'========================================================================
' THIS WILL RENAME ALL SHEETS IN A WORKBOOK TO THE VALUE IN B2 OF THE SHEET
' BEWARE OF ERRORS IF DUPLICATE
'========================================================================
    For Each Sheet In Sheets
        Sheet.Name = Sheets(Sheet.Name).Range("B2").Value
    Next Sheet
End Sub
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'========================================================================
' THIS WILL RENAME THE SHEET TO A CELL VALUE WHEN THE CELL VALUE CHANGES
' MUST GO ON SHEET NOT IN MODULE
'========================================================================
    If Target.Address <> "$B$2" Then Exit Sub
    On Error Resume Next
    ActiveSheet.Name = Range("B2")
End Sub
 
Upvote 0
ADVERTISEMENT
Mark

Thank you for responding and I confirm that for text items this works fine.

The problem I have is that the value in cell B2 is a date and it seems that however I type it in or press Ctrl ; it doesn't work. I have the cell formatted dddd dd mmm yy.

Lapta301
 
Upvote 0
Try

Code:
ActiveSheet.Name = Format(Range("B2").Value, "dddd dd mmm yy")
 
Upvote 0
ADVERTISEMENT
VoG

That's it, wonderful. Works a treat

I've said it before and I'll say it again you're a genius along with others on the Board.

Sincere thanks


Lapta301
 
Upvote 0
This is an old thread but just wanted to say thank you, the solution worked for me too. I've been searching for a code that worked for ages and finally found it. Much appreciated.
 
Upvote 0

Forum statistics

Threads
1,196,462
Messages
6,015,390
Members
441,890
Latest member
Liero131313

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