简体   繁体   English

Excel-从一年中的任何一天开始查找特定月份的第n天

[英]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. 我的问题:从11月的第一个星期日开始,一个职位不需要一直都配备人员。 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() ) 我希望根据今天的日期对显示该位置的框进行有条件的格式设置(在E1中使用= 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. 它似乎在11月的第二个星期日开始。 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. 牢记这一点,我已经开始感到有些不适了,我相信VBA可以轻松做到这一点,但是我不知道我在做什么的第一件事,这意味着如果有任何错误因为有人不小心删除了某些内容,所以我无法修复它。

TL;DR: Trying to hit a moving target of a date based off of a dynamic entry in E1. TL; DR:根据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) 根据E1,找到11月的第一个星期日和次年3月的第二个星期日(或者我想当我们回退到1月时是本年)

=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(). 或者,您可以将公式中的E1替换为TODAY()。 This equation will evaluate to True or False 该公式的计算结果为True或False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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