0

年の週をループする方法を見てきました、w1301、w1302、w1303、週番号で+をループすると週番号を取得できますが、vbaで毎週直接ループする方法があると思います、少なくとも願っています.

   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

日付から週番号の関数を取得しました

     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
4

3 に答える 3

1

DateAdd 関数を使用できます

For i = 1 To 52  
    Debug.Print DateAdd("ww", i, Now())  
Next i
于 2013-08-28T23:48:05.337 に答える
0

私はこのソリューションを試してみましたが、うまくいくようです。異なる月の28、30、31日をどのように処理するかは100%確信が持てませんが、vbaを信頼しています。私はおそらく間違いを犯していることを知っています:))

  currentDate = "2013-01-02"    ' coz i wanted to start on a wednesday
  for week = 1 to 52
  debug.print currentDate
  currentDate = DateAdd("ww",1,currentDate)
  next week
于 2013-08-29T20:57:44.553 に答える