+ Reply to Thread
Results 1 to 7 of 7

Copy only active sheet 1 and paste into other workbook after or before n sheets

  1. #1
    Registered User
    Join Date
    02-17-2011
    Location
    india
    MS-Off Ver
    Excel 2016 (home & student version)
    Posts
    79

    Copy only active sheet 1 and paste into other workbook after or before n sheets

    Hi All,

    Kindly help me out i m trying to copythe active sheet in source workbook and poaste it into another book after or before available sheets.
    i have used the code but getting the error "run time error 9 subscript out of range."
    this is the code

    Sub CopySheetToOtherWbk()
    Dim CopyFromBook As Workbook
    Dim CopyToWbk As Workbook
    Dim ShToCopy As Worksheet

    Set CopyFromBook = Workbooks("Invoice.xlsm")
    Set ShToCopy = CopyFromBook.Worksheets("Invoice")

    Set CopyToWbk = Workbooks("D:\Invo\test.xlsx")
    '
    ShToCopy.Copy After:=CopyToWbk.Sheets(CopyToWbk.Sheets.Count)
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Copy only active sheet 1 and paste into other workbook after or before n sheets

    Is 'test.xlsx' open?

    If it is then you don't need the file path to refer to it.
    Please Login or Register  to view this content.
    If it isn't then you need to open it.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: Copy only active sheet 1 and paste into other workbook after or before n sheets

    Did you open the target workbook?
    both workbooks must be open.

  4. #4
    Registered User
    Join Date
    02-17-2011
    Location
    india
    MS-Off Ver
    Excel 2016 (home & student version)
    Posts
    79

    Re: Copy only active sheet 1 and paste into other workbook after or before n sheets

    thanks it worked
    i missed the open. command
    can u tell me how to rename it automatically when it copy to the file from particular cell value

  5. #5
    Registered User
    Join Date
    02-17-2011
    Location
    india
    MS-Off Ver
    Excel 2016 (home & student version)
    Posts
    79

    Re: Copy only active sheet 1 and paste into other workbook after or before n sheets

    ok.
    no target workbook is closed only.
    thanks for ur quick reply

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Copy only active sheet 1 and paste into other workbook after or before n sheets

    You can't rename it 'automatically' but it's pretty straightforward to rename it, where is the new name stored?

  7. #7
    Registered User
    Join Date
    02-17-2011
    Location
    india
    MS-Off Ver
    Excel 2016 (home & student version)
    Posts
    79

    Re: Copy only active sheet 1 and paste into other workbook after or before n sheets

    In the same sheet

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA COde For copy and paste B column of every sheets to new workbook in one sheet
    By Chetan_raghu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2016, 02:22 PM
  2. Copy values from sheets in workbook and paste in one sheet in the same workbook
    By RinorM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-08-2015, 04:14 AM
  3. [SOLVED] Copy a sheet and paste in all sheets of workbook
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-15-2014, 06:49 AM
  4. Copy same range from multiple sheets and paste into one sheet of active workbook
    By jadown in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2013, 01:41 PM
  5. Open workbook, filter values, copy/paste into Active workbook.
    By niceguy21 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-10-2013, 12:17 PM
  6. Replies: 1
    Last Post: 01-08-2013, 03:38 AM
  7. Copy from active sheet and paste into new sheet using info from cell in active
    By Ingve in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2006, 06:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1