0 votes
in VBA by Beginner (13 points)
Hi guys

I have worked out how to rename worksheets (yay!)

But now am having a slight issue with an IF statement and was wondering if anyone would help.

If the very first sheet of the workbook is named "Sheet A", then I first rename the 3rd sheet to "Sheet X" and then rename "Sheet A" to something else. I don't know how to test the condition.

Can someone help?

Thanks!

1 Answer

+1 vote
by Super Expert (2.7k points)
selected by
 
Best answer

To rename the 1st and 3rd sheet based on the name of the first Excel sheet, the logic of your macro will look like this:

Sub RenameSheets()
If Sheets(1).Name = "Sheet A" Then
    Sheets(3).Name = "Sheet X"
    Sheets(1).Name = "Something Else"
End If
End Sub

 

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.

Register

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...