+ Reply to Thread
Results 1 to 10 of 10

VBA to check between two dates, compare with today and if true then copy entire data

  1. #1
    Registered User
    Join Date
    10-07-2022
    Location
    Cyyprus
    MS-Off Ver
    365
    Posts
    9

    VBA to check between two dates, compare with today and if true then copy entire data

    Hi All,

    I need a VBA code that will check between two dates (cells G & H in the attachment) and compare it with today's date. If true then extract data from entire row of a found match and paste it in a specific range.
    Or, alternatively, perhaps a conditional formatting in which I can paste entire data chart (for example A2-H6 in the attachment) and filter/show only data that matches today's date.

    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,787

    Re: VBA to check between two dates, compare with today and if true then copy entire data

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,787

    Re: VBA to check between two dates, compare with today and if true then copy entire data

    Here is an alternate solution for you

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: VBA to check between two dates, compare with today and if true then copy entire data

    Non looping option...
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  5. #5
    Registered User
    Join Date
    10-07-2022
    Location
    Cyyprus
    MS-Off Ver
    365
    Posts
    9

    Re: VBA to check between two dates, compare with today and if true then copy entire data

    Hey Alan,

    This code worked for me, the first one didn't, it would just highlight everything with red.

    Thanks a lot!

    Please Login or Register  to view this content.
    Last edited by alansidman; 10-16-2022 at 08:58 PM.

  6. #6
    Registered User
    Join Date
    10-07-2022
    Location
    Cyyprus
    MS-Off Ver
    365
    Posts
    9

    Re: VBA to check between two dates, compare with today and if true then copy entire data

    Hey Sintek,

    Thanks, for whatever reason it is missing out some entries, some rows have the correct data range and they should be copied to the second sheet but from 33 entries it is missing 6 of them all valid as compared with today's date.
    Any thoughts?

  7. #7
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Lightbulb Re: VBA to check between two dates, compare with today and if true then copy entire data

    Hello.
    Due to the regional configuration issue on my computer, what was proposed in post #5 does not work for me. So I expose another way that -it seems to me- works in all configurations:

    PHP Code: 
    Sub myFilter()
    Dim aQ&, i&, R&, j%
    With Sheets("Sheet1").Range("A1").CurrentRegion
      a 
    = .ValueUBound(a): .Rows(1).Copy Sheets("Sheet2").Range("A1")
    End With
    For 2 To Q
      
    If a(i7) <= Date And Date <= a(i8Then
        R 
    R: For 1 To UBound(a2): a(Rj) = a(ij): Next
      End 
    If
    Next
    With Sheets
    ("Sheet2")
      .
    Cells(1).CurrentRegion.Offset(1).Delete xlShiftUp
      
    If 0 Then .Cells(21).Resize(RUBound(a2)) = a
    End With
    End Sub 
    Last edited by beyond Excel; 10-16-2022 at 06:03 PM.

  8. #8
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: VBA to check between two dates, compare with today and if true then copy entire data

    Here is a solution with a formula that also copies the entire selection at once:

    Please try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,787

    Re: VBA to check between two dates, compare with today and if true then copy entire data

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)

    However, if you continue to not use code tags, you can expect to have your thread BLOCKED until you add them yourself.

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: VBA to check between two dates, compare with today and if true then copy entire data

    Quote Originally Posted by Vacheron23 View Post
    Hey Sintek,

    Thanks, for whatever reason it is missing out some entries
    Any thoughts?
    Works for sample...which are you testing against...Are the dates actual dates...
    Last edited by Sintek; 10-17-2022 at 02:22 AM.

+ 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: 11
    Last Post: 02-13-2022, 05:57 PM
  2. [SOLVED] VBA Simple Check if 2 cells matches and if that is true it will copy and paste data .
    By Desotronics in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-10-2019, 01:04 PM
  3. Replies: 0
    Last Post: 11-25-2014, 05:30 PM
  4. Compare a1 with entire column and return TRUE in b1
    By yiannis1925 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-12-2011, 01:08 PM
  5. copy entire data in a row when check box is enabled
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-01-2008, 03:01 PM
  6. copy data of check box is clicked true
    By pichai in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2008, 02:13 AM
  7. Compare dates with today()...
    By AMK4 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-30-2006, 03:34 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