Weekday Day of Month
If you like to list all Friday 13th between let's say 1-Mar-1900 and 5-Jun-2079 then you have several options. First enter start date into B1, end date into B2, weekday 6 (Friday) into B3 and day of month 13 into B4. Now you can:
a) Use worksheet functions:
a1) [Not recommended - too slow] Define name b: =ROW(INDIRECT(B1&":"&B2)) Define name s: =ROW(1:310) Now select 310 adjacent cells in a column and enter as array formula =LARGE(b*(WEEKDAY(b)=B3)*(DAY(b)=B4),s)
a2) [Not recommended - too slow] Define name d: =ROW(1:65536) Define name s: =ROW(1:310) Now select 310 adjacent cells in a column and enter as array formula =LARGE(d*(B1<=d)*(B2>=d)*(WEEKDAY(d)=B3)*(DAY(d)=B4),s)
b) [Recommended - not too fast but ok] Use a user-defined function: Select 310 adjacent cells in a column and enter as array formula =TRANSPOSE(weekday_dom(B1,B2,B3,B4)) Put macro text shown below into a macro module.
Please read my Disclaimer.
c) [If you really need a fast solution - but try to split the huge worksheet formula over several cells] Use a precalculated array with worksheet functions: Create a worksheet with name P, run VBA macro shown below, select 310 adjacent cells in a column and enter as array formula =IF(IF(ISERROR(MATCH($B$1,INDEX(P!$A$3:$HI$311,1,($B$4-1)7+$B$3):INDEX(P!$A$3:$HI$311,309,($B$4-1)7+$B$3),1)),0,MATCH($B$1,INDEX(P!$A$3:$HI$311,1,($B$4-1)7+$B$3):INDEX(P!$A$3:$HI$311,309,($B$4-1)7+$B$3),1))+ISERROR(MATCH($B$1,INDEX(P!$A$3:$HI$311,1,($B$4-1)7+$B$3):INDEX(P!$A$3:$HI$311,309,($B$4-1)7+$B$3),0))>MATCH($B$2,INDEX(P!$A$3:$HI$311,1,($B$4-1)7+$B$3):INDEX(P!$A$3:$HI$311,309,($B$4-1)7+$B$3),1),1/0,INDEX(P!$A$3:$HI$311,IF(ISERROR(MATCH($B$1,INDEX(P!$A$3:$HI$311,1,($B$4-1)7+$B$3):INDEX(P!$A$3:$HI$311,309,($B$4-1)7+$B$3),1)),0,MATCH($B$1,INDEX(P!$A$3:$HI$311,1,($B$4-1)7+$B$3):INDEX(P!$A$3:$HI$311,309,($B$4-1)7+$B$3),1))+ISERROR(MATCH($B$1,INDEX(P!$A$3:$HI$311,1,($B$4-1)7+$B$3):INDEX(P!$A$3:$HI$311,309,($B$4-1)7+$B$3),0)),($B$4-1)7+$B$3):INDEX(P!$A$3:$HI$311,MATCH($B$2,INDEX(P!$A$3:$HI$311,1,($B$4-1)7+$B$3):INDEX(P!$A$3:$HI$311,309,($B$4-1)7+$B$3),1),($B$4-1)7+$B$3))
Last updated