View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Worksheet copy with rename

Hi Doug,

You could do this a couple different ways, depending on whether you want a
copy of the first sheet, or if you want a new sheet with the data from the
first sheet copied onto it.

In either case, the sheet is renamed how you wanted. Here's a couple you can
try:


Sub CopyAndName()
' This creates a new sheet,
' copies the data from the first sheet,
' and renames it to a specified cell's value.

Dim sName As String, sht1 As Worksheet, sht2 As Worksheet

Set sht1 = ActiveSheet
sName = sht1.Range("A1").Value 'change the reference to your location
Set sht2 = Worksheets.Add(after:=ActiveSheet)
sht2.Name = sName
sht1.UsedRange.Copy Destination:=sht2.Range("A1")

End Sub



Sub CopyAndName2()
' This makes a copy of the ActiveSheet,
' and renames it to a specified cell's value

ActiveSheet.Copy after:=ActiveSheet

'At this point, it's the ActiveSheet,
'and contains the cell holding its name.
ActiveSheet.Name = Range("A1").Value 'change the reference to your
location

End Sub

Regards,
GS