+ Reply to Thread
Results 1 to 3 of 3

Code to copy and paste a data set into a different worksheet starting last row

  1. #1
    Registered User
    Join Date
    02-17-2010
    Location
    Brisbane Australia
    MS-Off Ver
    Excel 2016
    Posts
    45

    Code to copy and paste a data set into a different worksheet starting last row

    Hi all,

    I am trying to copy and paste a data set from a new file I receive weekly (Date_InfoPages) into a master file in a specific sheet (Info Pages) from the last row down. Basically add the new data every week at the bottom.
    I know I have put in the last row script yet however I cant seem to get this working.


    Dim WbThis As Workbook
    Dim WbDest As Workbook
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet

    '## Open both workbooks first:
    Set WbThis = Workbooks.Open("H:\Date_InfoPages.xls")
    Set WbDest = Workbooks.Open("H:\Dashboard MASTER.xlsx")

    Set ws1 = WbThis.Sheets("Date_InfoPages")
    Set ws2 = WbDest.Sheets("Info Pages")

    With ws1
    .Cells.Copy ws2.Cells
    WbThis.Close True
    WbDest.Close False
    End With


    Any help would be greatly appreciated.

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code to copy and paste a data set into a different worksheet starting last row

    Perhaps like this?

    Please Login or Register  to view this content.
    The command
    Please Login or Register  to view this content.
    will copy everything so if for example you have headings in row 1 you use the offset command to avoid copying this i.e.
    Please Login or Register  to view this content.
    will not include 1st row when copying.

    The "xlPasteAll" may not be the right command if there are formulas in sheet "Date_InfoPages" then "xlPasteValues" may be better.

    If you have special formats you wish to copy as well when you use "xlPasteValues" then you need to do this in two steps

    Please Login or Register  to view this content.
    Finally as WbDest is the updated workbook I assume you wish to save the changes made to this workbook, the WbThis can be closed witout saving.

    Alf

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Code to copy and paste a data set into a different worksheet starting last row

    Thanks for feedback and rep

    If this solves you problem don't forget to mark thread "Solved" as per forum rules.

    Alf

    Ps
    To mark your thread solved do the following:
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

+ 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. [SOLVED] How do I copy and paste all the text starting with REF-?
    By Buzz57 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-03-2014, 07:42 PM
  2. Copy values from worksheet and paste to starting from 15th row.
    By turist in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-11-2013, 06:54 AM
  3. [SOLVED] Trying to find the right code to copy a column from one worksheet and paste to another
    By mw91 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-15-2013, 01:57 PM
  4. [SOLVED] Need Help w/ Code for Copy/Paste data for a Summary Worksheet
    By Langie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-26-2013, 05:21 PM
  5. [SOLVED] Code to copy, sort, paste data from one worksheet to another.
    By wheatgrass in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-03-2012, 11:08 AM
  6. Code to look up, copy, paste, sort data from one worksheet to another
    By wheatgrass in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-14-2012, 11:45 AM
  7. Vba code to copy and paste second visible cell to other worksheet range then the next
    By Justin25150 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2012, 09:03 AM
  8. Need VBA Code to copy paste rows from worksheet to another
    By amasulli in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2012, 02:16 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