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.
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!!!
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?
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 a, Q&, i&, R&, j%
With Sheets("Sheet1").Range("A1").CurrentRegion
a = .Value: Q = UBound(a): .Rows(1).Copy Sheets("Sheet2").Range("A1")
End With
For i = 2 To Q
If a(i, 7) <= Date And Date <= a(i, 8) Then
R = 1 + R: For j = 1 To UBound(a, 2): a(R, j) = a(i, j): Next
End If
Next
With Sheets("Sheet2")
.Cells(1).CurrentRegion.Offset(1).Delete xlShiftUp
If R > 0 Then .Cells(2, 1).Resize(R, UBound(a, 2)) = a
End With
End Sub
Last edited by beyond Excel; 10-16-2022 at 06:03 PM.
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.
Bookmarks