PDA

View Full Version : Solved: Quick Question - Easy, but not for me!



NateW
10-24-2007, 11:16 AM
Heya, Folks.

I would like to take worksheet "Nate", and make a copy of it in the same workbook, and call it "Old_Nate", without deleting "Nate". What would the code be for that?

Thanks!!

Nate.

NateW
10-24-2007, 11:22 AM
BTW, I cannot use a fixed range, as the range will be different each time this is run...so I'm hoping there's a way to copy the whole worksheet, not a range within the worksheet.....

lucas
10-24-2007, 11:42 AM
Sub AddNewSheets()
Dim TotalSheets As Variant
TotalSheets = Worksheets.Count
Worksheets("Nate").Activate
ActiveSheet.Copy after:=Worksheets(TotalSheets)
Worksheets("Nate (2)").Activate
ActiveSheet.Name = "Old_Nate"
' ActiveSheet.Name = "Old_Nate" & TotalSheets + 1
ActiveSheet.Visible = True

End Sub
comment this line:
ActiveSheet.Name = "Old_Nate"

and uncomment the line that is commented in the code to add several new ones called Old_Nate1, Old_Nate2, etc.

Bob Phillips
10-24-2007, 11:44 AM
Worksheets("Nate").Copy After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Old_Nate"

daniels012
10-24-2007, 11:46 AM
Try this:

Sub AddNate()
Nm = ActiveSheet.Name
NewNm = "Old_" & Nm
ActiveSheet.Copy Before:=Sheets(1)
ActiveSheet.Name = NewNm
End Sub


micahel

NateW
10-24-2007, 01:34 PM
XLD: I tried your code - and when I run it I get Runtime Error 9 - Subscript Out of Range. Here is the actual code example:


Worksheets("Gate Control").Copy After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Old_GateControl"


The debug points to the first line of that code. Any suggestions?

NateW
10-24-2007, 01:37 PM
Actually, I think I might be okay...used Lucas's code, and it worked. Thanks!!

daniels012
10-24-2007, 01:42 PM
Mine may be simpler. Without having to Activate sheets and all..
But I am good with whatever works.

michael:hi:

NateW
10-25-2007, 08:04 AM
Hey, Dan...thanks for the help...the other was the one I got to work first, so...hehe...if it ain't broke........ :)