Worksheet copy with rename
Hi George,
Thanks. At home both your functions and both mine work. Here,
your first one works fine and your second one does not rename.
Have tried it on a number of worksheets, none protected.
Thanks again. Still curious why it works on one machine and not
the other.
Thanks for your time.
"GS" wrote in message ...
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
|