我想从一系列日期中设置日期,然后循环浏览日期列表?

时间:2019-05-01 11:49:35

标签: excel vba

我想在代码中将sDate变量设置为来自某个范围内的日期列表。

我的代码只能使用一个日期,但是对于我一生来说,我不记得如何遍历日期列表。

当我在名为“ BusinessDate”的单元格中有一个时,它可以工作...

Public Function sGetDate () as Date
Dim DateRng as Range
Dim sDate as Date
Set DateRng = Sheets("Control").Range("BusinessDate")

我想我可以对列表中的10个日期进行循环这样的操作:

Public Function sGetDate () as Date
Dim DateRng as Range
Dim sDate as Date
Set DateRng = Sheets("Control").Range("BusinessDateList")

If i = 1 To 10
sDate = BusinessDateList(i)
Next i
End If

Once the date is set from the list, it can loop through the existing code.

This doesn't seem to work at setting the date, but I it's been so long since I have looked at any vba I can't think of where to start.  Any help would be great.

1 个答案:

答案 0 :(得分:-1)

尝试使用For Each

例如

Each c in DateRng
debug.print c.value
next