+ Reply to Thread
Results 1 to 11 of 11

VBA to copy most recent data

  1. #1
    Registered User
    Join Date
    03-20-2012
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    24

    VBA to copy most recent data

    Col A has dates and Col B has values
    Every day new data added to bottom row.
    Want VBA to copy the most recent 50 rows to C1:C50, D1:D50

  2. #2
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2504
    Posts
    19,338

    Re: VBA to copy most recent data

    A couple of formulas would also fill in the data automatically. The formula to populate column C with the most recent 50 dates could be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    The formula to populate column D with the most recent 50 values could be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  3. #3
    Registered User
    Join Date
    03-20-2012
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: VBA to copy most recent data

    Quote Originally Posted by JeteMc View Post
    A couple of formulas would also fill in the data automatically. The formula to populate column C with the most recent 50 dates could be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    The formula to populate column D with the most recent 50 values could be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Let us know if you have any questions.
    Beautiful; thank you.

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2504
    Posts
    19,338

    Re: VBA to copy most recent data

    You're Welcome and thank you for the feedback. Please take a moment to mark the thread as 'Solved' using the thread tools link above your first post. I hope that you have a blessed day.

  5. #5
    Registered User
    Join Date
    03-20-2012
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: VBA to copy most recent data

    Quote Originally Posted by JeteMc View Post
    A couple of formulas would also fill in the data automatically. The formula to populate column C with the most recent 50 dates could be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    The formula to populate column D with the most recent 50 values could be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Let us know if you have any questions.
    Only 1 problem. My dates do not include weekends and holidays. Your formula tries to assign these dates - #N/A

  6. #6
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2504
    Posts
    19,338

    Re: VBA to copy most recent data

    Try this for the date (C1 and down):
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    And this for the value (D1 and down):
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Last edited by JeteMc; 01-26-2017 at 07:11 PM. Reason: Added second formula

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2504
    Posts
    19,338

    Re: VBA to copy most recent data

    I forgot to account for holidays, so:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-20-2012
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: VBA to copy most recent data

    Quote Originally Posted by JeteMc View Post
    I forgot to account for holidays, so:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    The only problem is the date on the bottom is not today - it is the largest

  9. #9
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2504
    Posts
    19,338

    Re: VBA to copy most recent data

    In that event I would think that it would be good to use the following formula to find the last date in column A:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Then reference the cell containing that formula, N1 in the attached sample, inside the WORKDAY function of both formulas, as in:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    You could put the LOOKUP function in the formula, in place of N1, however that seems to slow the process down a lot, I believe that is because the formula in each of the 50 cells in looking to see the the last non-blank cell out of the one million plus rows in column A. As it is that only has to happen once. I hope that makes sense.
    Let us know if you have any questions.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    03-20-2012
    Location
    NC
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: VBA to copy most recent data

    Quote Originally Posted by JeteMc View Post
    I forgot to account for holidays, so:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Instead of your suggestion =LOOKUP(99^99,1/(A:A<>""),A:A) I used max(A:A). It's not important, the workday function did not know 9/5/11 was a holiday. Thanx for all your help and patience.

  11. #11
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2504
    Posts
    19,338

    Re: VBA to copy most recent data

    You're Welcome and I'm glad that you got a solution that works. I assume by "not important" that you have solved the holiday issue, and if so please take a moment to mark the thread as 'Solved' using the thread tools link above your first post. I hope that you have a blessed 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. copy only most recent data from one cell to another
    By codyryan in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-10-2016, 08:15 AM
  2. Replies: 2
    Last Post: 01-04-2016, 03:40 AM
  3. Copy and paste the most recent entered data from other worksheets to summary sheet
    By cvsrini in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-18-2013, 04:51 AM
  4. Find most recent matching row and copy subsequent rows between workbooks
    By HRDFCE in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2012, 09:02 AM
  5. Data tables update automatically with most recent data
    By jworkman7 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-29-2012, 03:54 PM
  6. Copy 2nd Most Recent Files along w/first
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2009, 04:37 PM
  7. Copy Most Recent File to another Directory
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-14-2009, 12:51 PM

Tags for this Thread

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