是否有可能保留循环的值并将其添加到下一轮循环中?我试图找出两列日期之间的差异,并将差异相加(以找到平均天数)。到目前为止我的代码是:
Sub macro1()
Dim d1
Dim d2
Dim i As Integer
Set wf = Application.WorksheetFunction
For i = 1 To 10
d1 = Cells(i, 1)
d2 = Cells(i, 2)
sdays = wf.NetworkDays(d1, d2)
Range("D4") = (the sum of the loops)
Next i
End Sub发布于 2015-03-24 10:35:49
试试这个变量SumOfDates在循环时跟踪您的日期和,然后将该值粘贴到范围D4中。
Sub macro1()
Dim d1
Dim d2
Dim i As Integer
Dim SumOfDates
Set wf = Application.WorksheetFunction
SumOfDates =0
For i = 1 To 10
d1 = Cells(i, 1)
d2 = Cells(i, 2)
sdays = wf.NetworkDays(d1, d2)
SumOfDates = SumOfDates + sdays
Next i
Range("D4").Value = SumOfDates
End Subhttps://stackoverflow.com/questions/29229866
复制相似问题