Copy Worksheet

nh1234

Registered User.
Local time
Yesterday, 16:33
Joined
Dec 27, 2005
Messages
26
Hi,

I have an excel workbook with several worksheets. I have a coded command button that copies worksheet2, no problem. However, how do I change my code to have the worksheets copy in order after Worksheet2: worksheet3, worsheet4, worksheet 5....

Below is the code I am using which adds the copy at the end of the workbook:

Private Sub Copy_Worksheet_Click()
Dim result As String
ActiveWorkbook.Worksheets(2).Copy After:=Worksheets(Worksheets.Count)
End Sub

Any help is much appreciate!!!
 
Hi, nh,

please mind the slight difference between ActiveWorkbook (with the focus) and ThisWorkbook (with the code). In the sample code a workbook will be opened and the worksheet copied after all worksheets inside that workbook:

Code:
Private Sub Copy_Worksheet_Click()
Dim wkb As Workbook
Set wkb = Workbooks.Open("E:\Temp\User18.xls")
ThisWorkbook.Worksheets(2).Copy After:=wkb.Worksheets(wkb.Worksheets.Count)
Set wkb = Nothing
End Sub
Ciao,
Holger
 
Hi,

Thank you that was very helpful.
 

Users who are viewing this thread

Back
Top Bottom