VBA Date Function

jhmathis

New Member
Joined
Feb 25, 2023
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
Hello,

I'm wondering if it's possible to create macro with a date function that would get a range of rows as specified by a date range. For example, I have an Excel file that has a column of dates in the format of x/xx/xxxx; now let's suppose today's date is 2/25/2023 and I'd like to get all the data (rows) between last week Friday (2/17/2023) and this past Thursday (2/23/2023). Basically I'm looking for a function that will parse the date column and always find last week Thursday data (rows) to this week Friday for any given week. Appreciate any pointers and/or assitance with this

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hello,
Previous Thursday : =TODAY()-MOD(WEEKDAY(TODAY())+2,7)
Next Friday : =TODAY()+7-WEEKDAY(TODAY()+1)
 
Upvote 0
Do you strictly need vba code to do this? Is FILTER available in Excel 2021?
Here is a solution with Let and Filter, put any date in F1 and it will give you the week from Thurs thru Wed that that date is in.

Book1
ABCDEFGHI
1StartDay:Saturday, February 11, 2023
2
3DateData1Data2Data3
42023-01-26RXB500500DateData1Data2Data3
52023-01-27YHO3004002023-02-09YUG300300
62023-01-28KHF3003002023-02-10QYM400300
72023-01-29KLP3004002023-02-11AYE400300
82023-01-30MQD3004002023-02-12PAO500400
92023-01-31SDF3004002023-02-13MDE400300
102023-02-01BYV3004002023-02-14CVZ500400
112023-02-02DDT4004002023-02-15SFL300400
122023-02-03MHC300500
132023-02-04VII400300
142023-02-05WPU500500
152023-02-06DTR300500
162023-02-07BLG500400
172023-02-08KTW500500
182023-02-09YUG300300
192023-02-10QYM400300
202023-02-11AYE400300
212023-02-12PAO500400
222023-02-13MDE400300
232023-02-14CVZ500400
242023-02-15SFL300400
252023-02-16TLO400300
262023-02-17KHZ500500
272023-02-18UZJ400400
282023-02-19FAK400300
292023-02-20FTD300400
302023-02-21MXR500300
312023-02-22GGS300400
322023-02-23REZ500400
332023-02-24XLG400300
342023-02-25YEM300500
352023-02-26KFT400300
362023-02-27GPD400300
372023-02-28TMD300500
382023-03-01GRO500400
Sheet1
Cell Formulas
RangeFormula
F4:I11F4=LET( Top,$A$3:$D$3, Data,$A:$D, Dates,$A:$A, SearchDate,$F$1, Start,WORKDAY.INTL(SearchDate +1,-1,"1110111"), End,WORKDAY.INTL(SearchDate,1,"1110111"), Bottom,FILTER(Data,(Dates>=Start)*(Dates<End),""), VSTACK(Top,Bottom))
Dynamic array formulas.
 
Upvote 0
Solution
Do you strictly need vba code to do this? Is FILTER available in Excel 2021?
Here is a solution with Let and Filter, put any date in F1 and it will give you the week from Thurs thru Wed that that date is in.

Book1
ABCDEFGHI
1StartDay:Saturday, February 11, 2023
2
3DateData1Data2Data3
42023-01-26RXB500500DateData1Data2Data3
52023-01-27YHO3004002023-02-09YUG300300
62023-01-28KHF3003002023-02-10QYM400300
72023-01-29KLP3004002023-02-11AYE400300
82023-01-30MQD3004002023-02-12PAO500400
92023-01-31SDF3004002023-02-13MDE400300
102023-02-01BYV3004002023-02-14CVZ500400
112023-02-02DDT4004002023-02-15SFL300400
122023-02-03MHC300500
132023-02-04VII400300
142023-02-05WPU500500
152023-02-06DTR300500
162023-02-07BLG500400
172023-02-08KTW500500
182023-02-09YUG300300
192023-02-10QYM400300
202023-02-11AYE400300
212023-02-12PAO500400
222023-02-13MDE400300
232023-02-14CVZ500400
242023-02-15SFL300400
252023-02-16TLO400300
262023-02-17KHZ500500
272023-02-18UZJ400400
282023-02-19FAK400300
292023-02-20FTD300400
302023-02-21MXR500300
312023-02-22GGS300400
322023-02-23REZ500400
332023-02-24XLG400300
342023-02-25YEM300500
352023-02-26KFT400300
362023-02-27GPD400300
372023-02-28TMD300500
382023-03-01GRO500400
Sheet1
Cell Formulas
RangeFormula
F4:I11F4=LET( Top,$A$3:$D$3, Data,$A:$D, Dates,$A:$A, SearchDate,$F$1, Start,WORKDAY.INTL(SearchDate +1,-1,"1110111"), End,WORKDAY.INTL(SearchDate,1,"1110111"), Bottom,FILTER(Data,(Dates>=Start)*(Dates<End),""), VSTACK(Top,Bottom))
Dynamic array formulas.
Thanks
 
Upvote 0
My Pleasure. Happy to help. Best wishes.
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top