VBA

D

dipsy

I get error at the following line of my code:

Sheets("2004 (2)").Name = "2004Data"

I have sheet - 2004. I copied that sheet. So now in
Excel the copy is 2004(2). I want to rename it
to "2004Data".

The above code gives me a Run time error - 1004 -
Application defined or object defined error.

TIA for the help.
 
I

igor

the reason it may not work is because you have a sheet
with this name already. and it cannot create 2 sheets with
the same name.

it worked for me on office 97,2000,xp, and 2003
 
D

Dave Peterson

Instead of referring to the name of the newly copied sheet, you could rely on
the fact that the copied sheet is now the activesheet.

worksheets("2004").copy after:=worksheets("2004")
activesheet.name = "2004Data"

But this won't help if the real problem is that you already have a 2004Data
there.
 
Top