Macro To Rename Sheets

Moogie

New Member
Joined
Sep 16, 2002
Messages
47
Greetings,
The following macro renames the active sheet in a workbook to what is in cell A1 of that active sheet. I need this macro to work on each sheet in my workbook.
Dim MyName
MyName = ActiveSheet.Range("A1").Value
ActiveSheet.Name = MyName
Any help is greatly appreciated.
Thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
You cannot name any sheets with a name that is used already! Only one sheet per name? JSW
 

Moogie

New Member
Joined
Sep 16, 2002
Messages
47
Greetings Joe,
Guess I should explain this a bit. There will be about 500 sheets in the workbook. Each sheet's A1 value will be a different name. I just need this macro to rename each sheet whatever value is in that sheet's A1 cell.
Thanks in advance for your help.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,116
Office Version
  1. 365
Platform
  1. Windows
Try this code:

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Name = Sheets(WS.Name).Range("A1").Value
Next WS

Hope this helps.
 

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339

ADVERTISEMENT

Try the following, as Joe said though, if you try and name two sheets the same this will come to a grinding halt....

<pre>
Public Sub RenameSheets()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
ws.Name = ws.Range("A1")
Next ws

End Sub
</pre>
 

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
Actually, bearing that in mind, and the possibility of using an illegal name, the following might be better: -
<pre>
Public Sub RenameSheets()
Dim ws As Worksheet

On Error GoTo ErrTrap
For Each ws In ThisWorkbook.Worksheets
ws.Name = ws.Range("A1")
Next ws

On Error GoTo 0
Exit Sub

ErrTrap:
MsgBox "Unable to rename sheet " & ws.Name & " to " & ws.Range("A1")
Resume Next

End Sub
</pre>
 

Forum statistics

Threads
1,148,018
Messages
5,744,355
Members
423,863
Latest member
teehexcel

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