[英]Finding the week number of the quarter in Excel VBA
I need a VBA function that will return the week number in a quarter from a given date. 我需要一个VBA函数,该函数将从给定日期返回四分之一的星期数。
For example, Input of 1/1/2016 will return 1, 1/4/2016 will return 2, 10/1/2016 will return 1, 10/7/2016 will return 2, 11/11/2016 will return 7 例如,输入1/1/2016将返回1,1 / 4/2016将返回2,10 / 1/2016将返回1,10 / 7/2016将返回2,11 / 11/2016将返回7
I have a function in Excel that does this: 我在Excel中具有执行此操作的功能:
=IF(O48="","",WEEKNUM(O48)-WEEKNUM(LOOKUP(O48,DATE(YEAR(O48),{1,4,7,10},1)))+1)
But I am struggling to port it to VBA. 但是我正在努力将其移植到VBA。 Help? 救命? Thanks! 谢谢!
You can use DatePart
to get the week number in the year, then subtract 13 weeks for each quarter (also available with the DatePart
function): 您可以使用DatePart
获取一年中的星期数,然后为每个季度减去13周(也可以通过DatePart
函数使用):
Public Function WeekOfQuarter(inValue As Date)
WeekOfQuarter = DatePart("ww", inValue) - ((DatePart("q", inValue) - 1) * 13)
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.