+ Reply to Thread
Results 1 to 9 of 9

help with vba code pasting data to last row

  1. #1
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2016
    Posts
    954

    help with vba code pasting data to last row

    Hello, I was hoping someone could assist me with editing my code so it the second macro when called would paste the data underneath the data pasted from the 1st macro.

    The 1st macro pulls data from a closed workbook and it will copy day from A1 to X40000. There may be only data to row 25000, but the 40000 is just in case there is more data when report ran next, etc. The macro will paste this data on the workbook the macro is open and called from and then after pasting the initial data, the macro will call a 2nd macro, which will open a different workbook a copy that data. I need the 2nd macro though to be able to find the last row of data from column A and paste this new data underneath the data from the 1st copied data. Hope this makes sense. I have bolded the part that I have tried to make it locate the last row, but I keep getting errors. Any assistance resolving this issue would be greatly appreciated!

    Here is my code:
    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: help with vba code pasting data to last row

    You can determine the last row using count

    '1. Find last used row in the copy range based on data in column A
    lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row

    You can then replace that 40000 value with the variable "lCopyLastRow "

  3. #3
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2016
    Posts
    954

    Re: help with vba code pasting data to last row

    cubangt-Thank you for your suggestions! Could you demonstrate what I would need to do with the code above? I apologize, but I'm vba challenged and I found this code online. the 1st macro works great, but this is the 1st time I'm trying to run it twice per se to get data stacked on top of each other from 2 separate workbooks. Thanks again!

  4. #4
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: help with vba code pasting data to last row

    I updated your code:

    So whats the purpose of the two routines? Seems you are opening one file to get the data, then pasting it in the second file, is that correct?

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2016
    Posts
    954

    Re: help with vba code pasting data to last row

    Yes, that is correct. Due to the nature of the two reports the data has to be stacked from 2 separate reports, so this data can be analyzed correctly. Thank you for helping with the code. I just tried implementing it and it was hung up at the same code in the 2nd macro:
    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: help with vba code pasting data to last row

    Is this a valid sheet in your file?
    Set sh = Sheet16

    Also, what is that line doing, since right after you are closing the workbook?
    sh.Cells(Rows.Count, "A").End (xlUp)

  7. #7
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2016
    Posts
    954

    Re: help with vba code pasting data to last row

    cubangt- It is a valid worksheet, but it is labeled "Employer NCP" on the tab. The workbook that uses this macro remains open. The macro(s) are pulling data from other workbooks that are closed from worksheets titled "Report 1". So when the 1st macro is called it opens the 1st closed workbook/report and copies the data from the given range and pastes it in my open main workbook (where the macro button is on) and then that workbook that I just received the data from closes again, per the macro instruction. It should then call the 2nd macro to do the same thing, but I wasn't sure how to get the data to copy that data beneath the data just brought over from the 1st report.

    Currently your code copies the 1st row of headers and then it errors on that particular last row code. Although I should have had the data visible from the 1st report before getting that error. Hope that explains it better.

  8. #8
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: help with vba code pasting data to last row

    Well im literally working on a similar thing myself for our reports here..
    And this code works great for me, i only have to open my template and click the macro button, it will then open my other file on the network and copy the data into the template.. and when i run it again and again, the new data is appended to the end of the last rows.

    Please Login or Register  to view this content.
    Try modifying this above code for your purposes.

  9. #9
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2016
    Posts
    954

    Re: help with vba code pasting data to last row

    Thanks a lot cubangt!! Sorry for belated reply has been a long day.

+ 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. Need help with VBA code which allows copying pasting data between sheets if conditions met
    By huimincrystal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2019, 01:08 PM
  2. [SOLVED] Code not pasting matched data correctly
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-19-2018, 09:27 PM
  3. [SOLVED] VBA Code: Pasting Data to Another Sheet
    By Jim Clayton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2018, 04:14 PM
  4. [SOLVED] Code to delete data prior to pasting new data is REALLY slow
    By Reapz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-19-2015, 04:41 PM
  5. [SOLVED] -
    By indky in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-07-2012, 08:17 PM
  6. Code not copying and pasting data - basic error?
    By Kayote in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-23-2008, 10:57 AM
  7. running code after pasting data
    By lallen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-27-2005, 03:10 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