Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to copy and rename worksheet 1

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
US
Is there a way to copy and rename the copied worksheet in the same line of code?

I know about doing this:
Sheets("Base").Copy Before:=Sheets("Base")
Sheets("Base (2)").Name = MySheetName

But is there a better way to do it?
 
Hi,
The "better" way is to use as few hard names as possible. The only hard names you need are the name of the sheet to be copied and the name of the sheet that is copied.

Code:
'
    Dim IsName As String, ToBeName as String
'...
    Sheets(IsName).Copy After:=Sheets(Sheets.Count)
    Sheets(Sheets.Count).Name = ToBeName


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top