|
如附件所示,代码基本写出来了,但是有点小问题,需求:根据开始日期和结束日期,也就是C列和D列的日期,写出对应的收入开始日期和收入确认日期
代码如下:
Sub GenerateIncomeDates()
Dim startDate As Date
Dim endDate As Date
Dim incomeStartDate As Date
Dim incomeConfirmDate As Date
Dim monthCount As Integer
Dim i As Integer
' 获取开始日期和结束日期
startDate = Range("C2").Value
endDate = Range("D3").Value
' 计算开始日期和结束日期之间的月数
monthCount = DateDiff("m", startDate, endDate)
' 生成收入开始日期和收入确认日期的表
For i = 0 To monthCount
incomeStartDate = DateAdd("m", i, startDate)
incomeStartDate = DateSerial(Year(incomeStartDate), Month(incomeStartDate), 1)
incomeConfirmDate = DateSerial(Year(incomeStartDate), Month(incomeStartDate) + 1, 0)
Range("A2").Offset(i, 0).Value = incomeStartDate
Range("B2").Offset(i, 0).Value = incomeConfirmDate
Next i
End Sub
运行结果是,只运行C2单元格和D3单元格的,但是我的开始起始日是在整列的,这个要怎么改呀。
|
|