+ Reply to Thread
Results 1 to 19 of 19

Extract and copy data between two dates and paste them in another workbook

  1. #1
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Extract and copy data between two dates and paste them in another workbook

    Hi Everybody,

    Please help me to have a macro for the below procedure;

    let me explain. Say book1 has total 12 sheets named S1 to S12. Each Sheet contain data date wise, in the data column C has dates and rest of the columns upto CG have data against dates. I need your help to have a macro that pop up message to select start date and end date, it should copy the entire row between dates selected and paste them into another workbook say book2 containing 12 sheets named S1 to S12. Book1, S1 data should go to Book2, S1 and so on."

    Regards
    Quaidian

  2. #2
    Registered User
    Join Date
    05-11-2015
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    27

    Re: Extract and copy data between two dates and paste them in another workbook

    Interesting challenge -- filtering a "master" workbook to get subsets of data is one place where VBA really shines!

    I wrote a step-by-step guide to the solution below, with screenshots and animations, here:

    How to Copy Data to a New Workbook Based on Dates

    Assuming you paste the following heavily-commented code into your "master" workbook, which is the one containing ALL the data, you should be all set!

    Please Login or Register  to view this content.
    VBA demystified:
    HTML Code: 

  3. #3
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    Hi danwagner,

    thank you for reply.

    it is creating book and sheets but do not copy data to sheets.

    please guide.

    regards
    quaidian

  4. #4
    Registered User
    Join Date
    07-31-2015
    Location
    US
    MS-Off Ver
    Half Life 3
    Posts
    4

    Extract and copy data between two dates and paste them in another workbook

    This Vlookup function affects the data if we want to copy from two excel sheets. So instead of Vlookup, please advice how to copy and paste in master sheet from source file if it matches.

  5. #5
    Registered User
    Join Date
    05-11-2015
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    27

    Re: Extract and copy data between two dates and paste them in another workbook

    Hey @forquaidian -- very interesting. Is no data at all copied from the master workbook to the new workbook, or is it perhaps just the header row?

    I suggest putting break points on this section:

    Please Login or Register  to view this content.
    and stepping through it line by line, like this:

    2-minute Video of stepping through break points on Filter / Copy Steps

    This should show you if you are perhaps selecting a date range that is not contained in the master workbook.

    Hey @SSndstorm -- I'm not sure I understand your comment. There are no VLookup functions being applied here, but rather Excel AutoFilter function. This function application is cleaned up for each sheet by the following lines:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Extract and copy data between two dates and paste them in another workbook

    Maybe:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    Hi John,

    thank you for your mail.

    it is giving error "Type mismatch" at this line "If CDate(.Sheets(i).Cells(x, "C")) > start And CDate(.Sheets(i).Cells(x, "C")) < finish Then"

    It will work i believe, please note that my data starts at row # 5 and column # 2 and date column is # 3.

    please advise. i will be grateful to you.

    regards
    quaidian
    Last edited by forquaidian; 09-01-2015 at 05:26 AM.

  8. #8
    Registered User
    Join Date
    05-11-2015
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    27

    Re: Extract and copy data between two dates and paste them in another workbook

    please note that my data starts at row # 5 and column # 2 and date column is # 3.
    That is a very important consideration -- the position of the data on each Worksheet is critical for the
    Please Login or Register  to view this content.
    method to work correctly.

    The code below worked on my file after position all my data blocks to start in row 5, column 2. Here is a short video of the code in action:

    Copying data that starts in row 5, column 2 to a new workbook

    And here is the modified code:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    Hi Danwagner,

    Thank you for your reply, I appreciate your help.

    this is not fulfilling my requirement. it is creating new book which i do not need. i already has setup two books. secondly it loops through all sheets but not through S1 to S12 which is not needed.

    now it is copying the data but into new book.

    can you please rework for me?

    i will refer to the reply by John. he has some simple code but the problem with that code is

    "it is giving error "Type mismatch" at this line "If CDate(.Sheets(i).Cells(x, "C")) > start And CDate(.Sheets(i).Cells(x, "C")) < finish Then"

    please advise.

    nice to have replies from you.

    best regards
    Quaidian

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Extract and copy data between two dates and paste them in another workbook

    Try:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    Hi John,

    it is copying only one row but not copying all rows between dates.

    i am anxiously waiting for your reply.

    regards
    Quaidian
    Last edited by forquaidian; 09-04-2015 at 03:02 AM.

  12. #12
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    Hi Danwagner

    i am waiting for your reply?

    Regards
    Quaidian

  13. #13
    Registered User
    Join Date
    05-11-2015
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    27

    Re: Extract and copy data between two dates and paste them in another workbook

    Hey @forquaidian -- OK, I now understand more about your problem. You (1) already have the two Workbooks and (2) already have matching Worksheets between them.

    Do the Worksheets in the Destination Workbook (which is where we will paste our data to) already have data present? If so, does this data need to be cleared?

    At this point it would be very beneficial if you could provide samples, with the present state of the Workbooks and the desired "end" state of the Workbooks.

  14. #14
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    Hi Danwagner,

    sorry for replying late. i was on some business trip.

    please find the attachment. i have made it easy. i need a macro that pop-up message please specify date when date is entered it should recognize that specific rows containing that date in column C, it should leave that data as such and clear all other data (this must clear data not delete rows) in all worksheets that is from S1 to S12.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    hi Danwagner,

    i am still waiting for your reply.

    regards
    Forquaidian

  16. #16
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    Hi Danwagner,

    Is this not possible?

    Regards
    forquaidian

  17. #17
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    Hi Danwagner,

    is this not possible?

    Regards
    foquaidian

  18. #18
    Registered User
    Join Date
    05-11-2015
    Location
    Chicago, IL
    MS-Off Ver
    2013
    Posts
    27

    Re: Extract and copy data between two dates and paste them in another workbook

    The modified code below will:
    1. Prompt you to enter a date (this is the date you would like to keep)
    2. Validate the input date
    3. Loop through each Worksheet, clearing all rows that do NOT match this date

    This has a few important changes from the original design. First, it no longer copies data to a new Workbook. Second, it clears rows that do not match the input date (instead of deleting them). Finally, it prompts the user for a single input date for matching purposes, rather than two.

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    11-12-2013
    Location
    lahore pakistan
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Extract and copy data between two dates and paste them in another workbook

    Hi Danwagnerco!

    it is perfectly working.

    I am grateful to you.

    Regards
    Rahat

+ 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: 10-28-2014, 09:53 AM
  2. [SOLVED] Macro to find data in source workbook and copy paste to target workbook
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-23-2014, 06:21 AM
  3. Replies: 6
    Last Post: 03-26-2014, 11:40 PM
  4. Extract data from closed workbooks and copy into new workbook
    By philaugust2004 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-15-2013, 07:45 AM
  5. Replies: 6
    Last Post: 01-29-2013, 07:01 AM
  6. Extract data to new workbook based on two dates
    By jacol in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2012, 02:30 PM
  7. Replies: 3
    Last Post: 07-29-2012, 05:05 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