Excel中有一个优惠券功能,它给出了下一张优惠券的日期(coupncd),但该日期与到期日相同(到期日为15/02/2020,因此下一个优惠券日期应为15 / 02/2019)。但是,我想要的是相反的,因为优惠券的日期与结算日期相同。
我尝试创建此代码,但它无法正常工作。我将非常感谢你的帮助。
Function coupdate(settlement As Date, maturity As Date, frequency As Integer) As Date
Dim today As Date
Dim n As Integer
Dim newdate As Date
today = Now()
n = Application.WorksheetFunction.Round((today - settlement) / 364, 0)
i = n
j = Application.WorksheetFunction.Round((maturity - today) / 364, 0)
For i = n To j
newdate = DateAdd("m", ((i * 12) + frequency), settlement)
i = i + (frequency / 12)
Next i
coupdate = newdate
End Function