简体   繁体   中英

Excel - Finding nth day of specific month from any day of the year

I'm creating a daily scheduling report. Not every position in the report has to be staffed every day, but there's rules determining this (daylight savings mostly) and I've been pulling my hair out trying to figure out a good way to do this that will make it anyone-proof for the person that needs to fill out the sheet on any given day.

My issue: Starting the first sunday in november, one position doesn't need to be staffed all the time. This continues until the second sunday in march. I want the box that shows this position to be conditionally formatted based on what today's date is (which is shown in E1 using =Today() )

I got something close to working (though it looks disgusting), and would cite sources, but I just came back to working on this project after a couple months of a different assignment:

=IF(MONTH(E1)>10,AND((DATE(YEAR(E1),11,1+7*1)-WEEKDAY((DATE(YEAR(E1),11,8-1))))<E1,E1<(DATE(YEAR(E1)+1,3,1+14*1)-WEEKDAY((DATE(YEAR(E1)+1,3,8-1))))),AND(DATE(YEAR((DATE(YEAR(E1),11,1+7*1)-WEEKDAY((DATE(YEAR(E1),11,8-1))))-1),MONTH((DATE(YEAR(E1),11,1+7*1)-WEEKDAY((DATE(YEAR(E1),11,8-1))))),DAY((DATE(YEAR(E1),11,1+7*1)-WEEKDAY((DATE(YEAR(E1),11,8-1)))))),E1<(DATE(YEAR(E1),3,1+14*1)-WEEKDAY((DATE(YEAR(E1),3,8-1))))))

It seems to kick in during the SECOND Sunday in November. I'm particularly flummoxed now. It's been an interesting intersection of "I'm pretty good with computers and layout design" and now all of a sudden diving deeper than I'd ever thought i'd go in excel. Keeping that in mind, I'm starting to feel a little out of my depth already and I'm sure VBA could do this easily but I wouldn't know the first thing about what I'm doing which means if anything ever goes wrong because someone accidentally deleted something I won't be able to fix it.

TL;DR: Trying to hit a moving target of a date based off of a dynamic entry in E1. Based off of E1 find the first sunday in november and the second sunday in March of the following year (or i suppose current year once we roll back around to january)

=OR(DATE(YEAR(E1),11,15-WEEKDAY(DATE(YEAR(E1),11,1),2))<=E1,DATE(YEAR(E1),3,15-WEEKDAY(DATE(YEAR(E1),3,1),2))>=E1)

alternatively you can replace E1 in the formula with TODAY(). This equation will evaluate to True or False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM