Home > Back-end >  How to properly rename a worksheet after adding as a new sheet?
How to properly rename a worksheet after adding as a new sheet?

Time:07-03

I would like to rename my worksheet but its not working. I can't seem to find the answer similar to my case yet. Here is my code

dim shNew as worksheet

set shNew = Sheets(3).copy(after:=Sheets(Sheets.Count))
shNew.name = Sheets(2).cells(1,2)

The code can run without any error but the name remain unchange for the new sheet.

CodePudding user response:

This worked for me:

Sheets(3).Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = Sheets(2).Cells(1, 2).Value

CodePudding user response:

I have the answer already thanks to @Tim Williams. As I only told shNew to add a new sheet for me, so shNew is just a command of adding a new sheet thus no value returned. With no value to 'rename', it did nothing for the rename line.

  • Related