worksheet copying error

  • Hello,


    I am recieving a "subscript out of range" error while trying to copy a sheet from one workbook to another. If someone could help me out that would be great


    thanks


    Code
    Set wb = Application.Workbooks.Open(ThisWorkbook.Path & "\" & ThisWorkbook.Worksheets("signoffs").Range("A2"))
        Set wb2 = Application.Workbooks.Open(ThisWorkbook.Path & "\template")
        wb2.Sheets("Template").Select
        wb2.Sheets("Template").Copy After:=Workbooks(ThisWorkbook.Path & "\" & ThisWorkbook.Worksheets("signoffs").Range("A2"))
        
        
        wb2.Close
  • Re: worksheet copying error


    Thanks for your help, i got it now.


    I have another question though: Is there a way for me to always copy the sheet to the end, since the names of the sheets in wb2 will always be different.


    thanks

  • Re: worksheet copying error


    I have not opened Excel to check, but try


    Code
    wb2.Sheets("Template").Copy After:=wb.sheets(wb.sheets.count)


    I can not remember if teh sheets collection is zero or 1 based. If it is zero based you will need to use .count-1.


    HTH,


    A.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!