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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You cannot name any sheets with a name that is used already! Only one sheet per name? JSW
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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>
 
Upvote 0
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>
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
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