Rename Worksheets Excel 2007

tf37

Board Regular
Joined
Apr 16, 2004
Messages
169
This macro works for the most part, but what happens is it doesn’t completely rename the entire sheet.
If the sheet name is “Sheet1” and you run the macro, it renames it to “Sheet71 1”
What am I missing here to get it to just rename the Sheet1 to Sheet71 without leaving the 1 after the rename?
If steps to the next sheet, like Sheet2 and renames it Sheet72 2 and so on.

Sub RenameSheets()
Dim ws As Worksheet

For Each ws In Worksheets
If ws.Name Like "Sheet#*" Then
ws.Name = Replace(ws.Name, "Sheet", "Sheet71 ", 1, 1)
End If
Next ws
End Sub
 
How about
Code:
Sub RenameSheets()
   Dim ws As Worksheet
   
   For Each ws In Worksheets
      If ws.Name Like "Sheet#*" Then
         ws.Name = "Sheet" & Split(ws.Name, "et")(1) + 70
      End If
   Next ws
End Sub
The code tags is the # icon in the reply window. Simply click the icon & then paste the code between them.
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
That did it just fine, thank you.
I'm still puzzled why the old macro didn't work when I'm pretty sure it was fine before.
I use to use it also to rename sheets from Sheet1...etc, to List1 List2 etc too, and perhaps that is where I'm mixing it up at.
I use the all this in compiling a jury wheel for prospective jurors, and go through sheet name changes from time to time.
Anyway, many thanks for all the help, and the code tag information :)
Terry
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,898
Members
452,948
Latest member
Dupuhini

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