Renaming Worksheets

Nathaniel

New Member
Joined
Mar 29, 2011
Messages
2
Sorry about this, I've seen a lot of people ask questions like this but I can't find one to do exactly what I want and was hoping you guys could help.
Code:
Sub nametab()
Dim s As String
Dim ss As String
s = ActiveWorkbook.Name
ss = Left(s, Len(s) - 4)
Sheets("Sheet1").Name = ss
End Sub
Is the code that I have been able to find which works fine for me, but I get sheets sent to me constantly where the sheet is called Sheet1, and other times its called Page1-1, and I having almost no experience with VB have no idea of what syntax or rules to follow to get "or" working in that 2nd last line.

So if anyone could show me what I need to rename both Sheet1 and Page1-1 to the filename that would be great.

Thanks,
Nathaniel
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I don't know much about VBA syntax, but can you use the LEFT function without the Worksheetfunction.left?
 
Upvote 0
Try:
Code:
ActiveSheet.Name = ss

Of course, so simple and I saw people using that in different much more complitcated (and much less complicated) scripts to rename the sheets and didn't think to try it.

Thanks heaps JoeMo.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

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