简体   繁体   English

相对于年份的动态周数

[英]Dynamic week number in respect to year

I'm trying to to retrieve monthly the week number of the year, sounds like a stupid question, but this is what I want to look like: 我试图每月检索一年中的周数,听起来像一个愚蠢的问题,但这就是我想要的样子:

在此输入图像描述

For the cell C1 I have created a drop down list based on B1 => =TEXT(TODAY();"[$-0809]mmmm") and also the Weeks (C2:C6) are retrieved by HLookup Function. 对于单元格C1我创建了一个基于B1 => =TEXT(TODAY();"[$-0809]mmmm")的下拉列表,并且还通过HLookup函数检索周(C2:C6)。

The idea is that I only need a dynamic Week format, such as C1:C6, but I didn't find another way outside the one I've used and I also need to transpose it in VBA . 我的想法是我只需要一个动态的周格式,比如C1:C6,但我没有找到另一种方法,而不是我用过的方法,我还需要在VBA中转置它。 Is there an easier method? 有更简单的方法吗? I could use your hints/ideas. 我可以使用你的提示/想法。 On a new sheet which is exported monthly I need to show the 4/5 weeks of each month, being different from month to month. 在每月导出的新工作表上,我需要显示每个月的4/5周,每个月都不同。

Use the Weeknum function: =WEEKNUM(DATE(2019,3,1),2) will return the first week of the month and =WEEKNUM(EOMONTH(DATE(2019,3,1),0),2) will return the last week of the month. 使用Weeknum函数: =WEEKNUM(DATE(2019,3,1),2)将返回该月的第一周并且=WEEKNUM(EOMONTH(DATE(2019,3,1),0),2)将返回本月最后一周。

So put … 所以......

  • in B2 =WEEKNUM(DATE(YEAR(TODAY()),$B$1,1),2 ) 在B2 =WEEKNUM(DATE(YEAR(TODAY()),$B$1,1),2 )
  • in B3 =IFERROR(IF(B2+1<=WEEKNUM(EOMONTH(DATE(YEAR(TODAY()),$B$1,1),0),2 ),B2+1,""),"") and pull it down to get the following result: 在B3 =IFERROR(IF(B2+1<=WEEKNUM(EOMONTH(DATE(YEAR(TODAY()),$B$1,1),0),2 ),B2+1,""),"")和拉下来得到以下结果:

在此输入图像描述

If you now change the month number in B1 it calculates the rest automatically: 如果您现在更改B1中的月份数,它会自动计算其余数字:

Note that there are different official week numbering systems, while the most common would be the ISO week date . 请注意,有不同的官方周编号系统,而最常见的是ISO周日期 That means that january 1st is not always week number 1! 这意味着1月1日并不总是第1周!

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

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