+ Reply to Thread
Results 1 to 7 of 7

Need vba-copy data from second row till last row & paste in another workbook after lastrow

  1. #1
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    Need vba-copy data from second row till last row & paste in another workbook after lastrow

    Hi All,

    Can I get vba code to copy data from excel starting from 2nd row (ie., to exclude headers) and paste the data in another workbook that already contains few rows of data. The tricky part is to paste the copied data after lastrow of destination workbook.

    Ex:
    1. I have mock_data workbook and that's the source data.
    2. In real time I will be having more than 100 columns but for example, I have included only few.
    3. Copy data from 2nd row till last row (but column range is dynamic. Its not fixed to 10 columns or 20 columns)
    4. Paste copied data to destination workbook towards end of row ie., lastrow + 1

    I really appreciate any help provided.

    Thanks,
    Richa
    Attached Files Attached Files

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need vba-copy data from second row till last row & paste in another workbook after las

    Something like this can do it. Just change filepath.

    Please Login or Register  to view this content.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    Re: Need vba-copy data from second row till last row & paste in another workbook after las

    Hi,
    Thanks for quick reply. I really appreciate Your help.
    In meantime, I tried to record the macro and below code was generated:
    Please Login or Register  to view this content.
    Can You please let me know if there's a way to use below line of code and modify it to suit my requirements?
    Please Login or Register  to view this content.
    I tried this approach as it does not consider column index or labels as reference. Say for example: .Range("A2:a100") and .Range("O" & unicorn.Row)).Copy

    Thanks,
    Richa

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need vba-copy data from second row till last row & paste in another workbook after las

    Yeah, you could skip the whole loop and do it all at once:
    Please Login or Register  to view this content.
    This UsedRange selects all of the data, and then resizes to omit the top row, and copies it all over at once.

  5. #5
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    Re: Need vba-copy data from second row till last row & paste in another workbook after las

    Thanks it worked. I also tried on my own by searching internet on how to replace recorded code with variables and I ended up with this:
    Please Login or Register  to view this content.
    It's working fine but will be glad if somebody optimize this code to single line or something better than this.

    Thanks,
    Richa

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Need vba-copy data from second row till last row & paste in another workbook after las

    That's pretty good. I usually only declare variables if I'm going to use them a few times.

    This works as well:

    Please Login or Register  to view this content.
    There are a few different copy and paste approaches. While you can copy and then paste on subsequent lines, the Copy method of the range object being used actually accepts the destination cell on the same line.

    Such that
    Please Login or Register  to view this content.
    will copy a1 to b1.

    The following line is doing the copy and the paste all in one go:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    Re: Need vba-copy data from second row till last row & paste in another workbook after las

    Wow! You are awesome and thank You so much for help and also for explanation. It work great. Am marking this thread as solved.

    Thanks,
    Richa

+ 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. Replies: 3
    Last Post: 11-20-2012, 02:25 PM
  2. copy cell and paste diwn till last row
    By dingdang in forum Excel General
    Replies: 1
    Last Post: 09-24-2012, 01:22 PM
  3. Copy and paste above row number and continue till end
    By MUNDHRA in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-17-2012, 05:01 AM
  4. Copy Paste and Loop till last column with data
    By eirumba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2011, 07:23 AM
  5. Copy and paste formula till the last row
    By vijanand1279 in forum Excel General
    Replies: 9
    Last Post: 01-05-2011, 01:26 PM
  6. Copy and Paste Multiple Cells in the same row till last Last Column
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2010, 03:40 PM
  7. Copy and Paste till last Last Column
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2010, 05:43 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