VBA Excel循环播放一年中的所有日子

时间:2013-04-04 13:06:55

标签: excel vba excel-vba

在Excel VBA中:

如何循环显示给定日期范围内的所有日期?

'2013-01-01'到'2013-01-03'应该给出:

2013-01-01
2013-01-02
2013-01-03

1 个答案:

答案 0 :(得分:11)

这至少应该告诉你如何开始你想要做的事情:

  Sub test()

  Dim StartDate As Date
  Dim EndDate As Date
  Dim DateLooper As Date

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

  For DateLooper = StartDate To EndDate
     MsgBox (DateLooper)
  Next DateLooper

  End Sub