lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
I opened a new file. has sheet1. I clicked on recording Macro. I clicked on + to add a new sheet. Then changed sheet name to XYZ. Then stopped the macro. So far so good, Now sheet XYZ is the active one. I now tried to run the same macro but this time, Sheet3 will be created but then I got error message. I checked the code below and I do not understand why it is not working. I thought this line could be an issue.
but what is wrong with renaming the same sheet with same name again? Or could be another line causing the macro can not run again. Thank you so much
I opened a new file. has sheet1. I clicked on recording Macro. I clicked on + to add a new sheet. Then changed sheet name to XYZ. Then stopped the macro. So far so good, Now sheet XYZ is the active one. I now tried to run the same macro but this time, Sheet3 will be created but then I got error message. I checked the code below and I do not understand why it is not working. I thought this line could be an issue.
Code:
Sheets("Sheet2").Name = "xyz"
Code:
Sub Macro1()
'
' Macro1 Macro
'
'
Sheets.Add After:=ActiveSheet
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "xyz"
Range("C5").Select
End Sub
Last edited: