lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
I wrote a macro that suppose to count how many sheets and then rename them to hello1, hello2, hello3 etc. I ran the code and it did work for the first time. for the next time after I added a new sheet (manually) when I ran the code I got an error message saying the name is already taken. How can I fix that? Thank you so much
I wrote a macro that suppose to count how many sheets and then rename them to hello1, hello2, hello3 etc. I ran the code and it did work for the first time. for the next time after I added a new sheet (manually) when I ran the code I got an error message saying the name is already taken. How can I fix that? Thank you so much
Code:
Sub renamesheets()
Dim x As Integer
Dim y As Integer
x = Worksheets.Count
For y = 1 To x
Worksheets(y).Name = "hello" & y
Next
End Sub