如何使用vba遍历日期范围内的几周 [英] How to loop through the weeks in a date range with vba

查看:60
本文介绍了如何使用vba遍历日期范围内的几周的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了如何循环一年中的几周 w1301、w1302、w1303,如果我在周数上循环 + ,我可以获得周数,但我相信有一种方法可以使用 vba 直接每周循环,我至少希望.

I have seen how to loop through weeks of a year, w1301,w1302,w1303, I can get the week number if i loop through + on week number but I believe there is a way to directly loop weekly with vba, i hope at least.

   DateSerial(Year(Now), Month(Now), Day(Now)) To DateSerial(2013, 3, 1)

    StartDate = #1/1/2013#
    EndDate = #12/31/2013#

  For DateLooper = StartDate To EndDate

我得到了从日期开始的周数的函数

I got the function for a week number from date

     Public Function IsoWeekNumber(d1 As Date) As Integer
     Attributed to Daniel Maher
     Dim d2 As Long
     d2 = DateSerial(Year(d1 - WeekDay(d1 - 1) + 4), 1, 3)
     IsoWeekNumber = Int((d1 - d2 + WeekDay(d2) + 5) / 7)
     End Function

推荐答案

您可以使用 日期添加函数

For i = 1 To 52  
    Debug.Print DateAdd("ww", i, Now())  
Next i

这篇关于如何使用vba遍历日期范围内的几周的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆