+ Reply to Thread
Results 1 to 14 of 14

Macro to copy and replace based on dates

  1. #1
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Macro to copy and replace based on dates

    I want a macro that will compare two different sheets. In both sheets column B will contain dates. I want the macro to look at sheet1 at the last row of data in column B and add 1 day. I then want it to go to sheet2 and look for this date and when it finds it copy all the data from then downwards to sheet1 at the very bottom.

  2. #2
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    Trying desperately to find a solution online but have come up blank! Anyone any knowledge of how i would do/start this?

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to copy and replace based on dates

    Do you have a sample file that you can upload?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    Here you go.

    sample.xlsm

  5. #5
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    So in the sample I've uploaded in Sheet1, look at the last row of data in column B and add 1 day to the date that you find. Then go to sheet2 and search for this date and when it finds the first instance of this date copy everything on that row and below it and paste it below the last used row in sheet1.

  6. #6
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    What about this workaround? Find the last date used in column B sheet 1 and add one day and paste the value in a random cell and then search for the date in the cell in sheet 2 and when found copy and paste that row and everything below to the bottom of sheet 1?

  7. #7
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    I've managed to come up with this which finds the last date in column B sheet 1 and pastes the value into sheet2.
    Please Login or Register  to view this content.
    I now want code that will Find the date in sheet2 which is now in cell W1 in sheet 2 and when it finds it copy that row and all rows below it that are in use.

  8. #8
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    Have gotten this far with the following but doesn't work although I think I'm on the right tracks. Any help fixing the below code??

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    Please Login or Register  to view this content.
    The above is causing the issue here with error message Object variable or With block variable not set.

  10. #10
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    The code below runs through and gives me the message box but doesn't paste everything below where it finds value W2 into the bottom of sheet1. Why?!?! I'm going crazy trying to work this one out!!!!!!!!!!
    Please Login or Register  to view this content.

  11. #11
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to copy and replace based on dates

    If you are going to cross post...

    I'm afraid your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
    HTH
    Regards, Jeff

  12. #12
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    http://www.mrexcel.com/forum/excel-q...find-copy.html

    The above link has the same issue with the most recent code that needs fixing so my macro will work

  13. #13
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Macro to copy and replace based on dates

    sample.xlsm

    This might make it simpler. Attached is a workbook with sheet1 and sheet2 and how sheet1 is supposed to look after the macro is run. The added data after the macro is run is in red font.

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to copy and replace based on dates

    So only 1 date should be added to sheet1? What if you have data till 11/12/2012 in Sheet 1 and data till 11/16/2012 in Sheet2. If you add one date in sheet1, it will be 11/13/2012. You find that data and copy. Then do you repeat and put in 11/14/2012? Till what date should the macro continue doing this?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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