View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default rename a copied sheet

Note that the copied sheet name Template (2) has a space.

Add that to your macro.

Private Sub copysht()
sname = "dog"
Sheets("Template").Copy after:=Worksheets(Worksheets.Count)
Sheets("Template (2)").Name = sname
End Sub


Gord Dibben MS Excel MVP

On Tue, 4 Mar 2008 12:18:13 -0800 (PST), wrote:

I am trying to write a simple VBA program for a spreadsheet. However
I
am stuck. I am learning this as I go along so that is the big problem
no doubt. I need to copy a sheet and rename. Simple eh? I copy it no
problem but cannot figure how to change the copyed name (now
firstname(2) for instance) to a new name. A cut out of the utility is
below:

Private Sub copysht()
sname = "dog"
Sheets("Template").Copy after:=Worksheets(Worksheets.Count)
'.name
= "sname" 'copy at the end
Sheets("Template(2)").name = "sname"
'ActiveWorkbook.Sheets("Template(2)").name = "sname" 'give sheet a
new
name but it blows up on Template(2)!
End Sub