VBA to rename

I have a workbook with 3 tabs which I need to rename. However, when the workbook is opened if someone has renamed them, I need to rename them when the workbook is opened. can this be done.

So, the three tabs are called i.e. yesterday, today, tomorrow. but when my macro opens the file the tabs have been re-named monday tuesday wednesday [but they could be called anything]

the macro now needs to re-name them yesterday, today, tomorrow and clear the data from all three tabs.

Is this doable with VBA and if so can someone provide this code please.

thanks
JagwarmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

unknown_routineCommented:
Yes it is doable.
Put the following code in the Workbook_Open.

Private Sub Workbook_Open()

Sheets(1).Name = "yesterday"
Sheets(2).Name = "Today"
Sheets(3).Name = "Tomorrow"
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rory ArchibaldCommented:
Assuming the code names of the sheet are unlikely to be changed by the user, you can use those:

Private Sub Workbook_Open()
With Sheet1
   .Name = "Yesterday"
   .Usedrange.ClearContents
End With
With Sheet2
   .Name = "Today"
   .Usedrange.ClearContents
End With
With Sheet3
   .Name = "Tomorrow"
   .Usedrange.ClearContents
End With
End Sub

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.