+ Reply to Thread
Results 1 to 26 of 26

Copy and paste based on Date.

  1. #1
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Copy and paste based on Date.

    I am currently trying to find an easier way to copy data source sheet to destination sheet based on date. But condition is source sheet “G” column will paste to destination sheet’s column “G” according to destination sheet’s “C” column. I am not able to make you understand that what I want. Here I attach two screenshot/file for your understanding. Can you help me to get the VBA code for copying the data which I shown the screenshot.
    your help is greatly appreciated as always!! thank you for your time!!!
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    Hi mazadb,

    Try below code ...
    Please Login or Register  to view this content.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  3. #3
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    Thank you for the Rep+

    If the provided solution takes care of your original question, please take a moment & mark this thread as [SOLVED] from the Thread Tools above your first post

  4. #4
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Hello,
    Thanks a lot for your help. The code you sent, it works very nicely. But it makes new problem. That is, source sheet name “P01” and destination sheet name “RiceMar21”. In you code, when I change source and destination like “P01” and “RiceMar21” then this code does not work at all. I addition, Source sheet’s “P01” data from “Register” sheet by filtering. Could you tell me what is the wrong ?
    your help is greatly appreciated as always!! thank you for your time!!!

  5. #5
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    Can you post the code after the changes you've done ? Also, when you say "does not work" what happens ? Do you get an error message ? What is it & at what line of code ?

  6. #6
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Here is code:
    Please Login or Register  to view this content.
    Last edited by mazadb; 04-30-2021 at 04:20 PM.

  7. #7
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    I tried your code again in the same sample file provided in post #1 & after changing the sheet names to "P01" & "RiceMar21" it ran as expected with no errors. Can you please tell me what is the error message you're getting & at which line of the code ?

    PS: Please edit you post #6, select your code then press the # button from the menu & it will insert code tags for you

  8. #8
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    It keeps giving me "Subscript out of range error" at line 4
    Last edited by mazadb; 04-30-2021 at 04:23 PM. Reason: Grammar mistake

  9. #9
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    The error you're probably means that you don't have that sheet name ! Check the attached file, I have changed the sheet names & it is working fine

    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    After some debugging I noticed r variable is always "Error 2042"
    the subscript out of range error was caused by an invisible character in the sheet name


    Please Login or Register  to view this content.
    Attachment 730660

  11. #11
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    The error means there's no match ... Can you post copy of your other sample file ?

  12. #12
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Here is the file.
    Attached Files Attached Files

  13. #13
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    Hi mazadb,

    I checked your file & found 2 macros with the name "Test" one under Sheet1 (P01) which is referencing Sheets("Purchase Register") and another macro called "Test" under Module1 which is referencing Sheets("P01") which is working fine. To avoid confusion, I suggest that you either delete the macro under Sheet1 (P01) or re-name it

  14. #14
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Hello,
    I have deleted macro macros with the name "Test" one under Sheet1 (P01) which is referencing Sheets("Purchase Register") and use macro "Test" under Module1. Then what happened look this screenshot.
    Attached Images Attached Images

  15. #15
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    Try below code, if my understanding is correct ...
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Hello, I have tried your new code. But it does not work. It’s look like this.
    Attached Images Attached Images

  17. #17
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    I think this will be an endless guessing/assumption game from my side ... Please put the expected data manually in sheet "RiceMar21" & upload a file

  18. #18
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Hello,
    Destination Sheet "RiceMar21" should be like this.
    Attached Images Attached Images

  19. #19
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    That doesn't make sense, the data in sheet P01 is in dates from 1-Mar until 7-Mar ... Please upload the excel file not a picture

  20. #20
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Hello,
    Here is the excel file.
    Attached Files Attached Files

  21. #21
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    mazadb, the structure of the file in post #20 is different than your initial post hence, the code didn't work. In the original file, the date was in column C and in your actual file the date is in column G ... Try below code, I have also attached the file for your reference

    Please Login or Register  to view this content.
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Yes, I got it. Thanks a lot. You are a genius. Actually I need you. Again thanks.

  23. #23
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Hello,
    I need little bit help. Could you explain the code: b = [transpose(row(3:14))] and r = Application.Match(CLng(c), Application.Index(a, 0, 6), 0) .
    Thanks.

  24. #24
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy and paste based on Date.

    Hi mazadb,

    I have added comments in each line of the code to explain .. Hope that helps
    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Hello,
    Thanks a lot.

  26. #26
    Registered User
    Join Date
    02-19-2017
    Location
    Helsinki, Finland
    MS-Off Ver
    MS Office 365
    Posts
    60

    Re: Copy and paste based on Date.

    Thanks a lot
    Last edited by mazadb; 05-10-2021 at 03:56 PM. Reason: Grammar mistake

+ 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 and Paste based on Date VBA
    By sjk1193 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2019, 07:20 AM
  2. copy paste based on a date
    By namluke in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-11-2015, 10:39 AM
  3. [SOLVED] Copy Paste Based on Date
    By RedMug in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-25-2014, 01:50 PM
  4. Vba to copy and paste based on date criteria
    By thedeadzeds in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-16-2014, 11:08 AM
  5. Copy Paste row from one worksheet to another based on DATE
    By niketmohan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2011, 08:29 AM
  6. Copy row based on date and then paste into a new worksheet based on section number
    By calmlaunch in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-25-2011, 11:40 PM
  7. Copy-Paste based on date in cell
    By yunesm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2009, 04:18 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