[英]Add month to previous cells date For each loop
All, 所有,
I have written a little procedure which I would like a for each loop to insert the current month into the first cell "01"/MM/YY and then add one month to the date as it goes through the loop. 我编写了一个小程序,我希望每个循环将当前月份插入第一个单元格“ 01” / MM / YY,然后在循环中向日期添加一个月。 Using the example below;
使用以下示例;
K1 = 01/06/2018
L1 = 01/07/2018
M1 = 01/08/2018 etc
The code I am using is below - The error is on the DateAdd
line. 我正在使用的代码如下-错误在
DateAdd
行上。
Sub test()
Dim dt As date
dt = "01/" & Application.Text(Now(), "MM/YY")
Dim i As Double
i = 1
For Each c In Range("K1:XFD1")
If c.Value = "" Then Exit For
c.Value = dt
'change date to one months time
dt = DateAdd(m, i, dt)
i = i + 1
Next c
End Sub
Any help regarding this would be much appreciated. 关于此的任何帮助将不胜感激。
Put "m"
not m
. 放
"m"
而不是m
。 m
would be a variable. m
将是一个变量。 "m"
is a literal string representing the argument being "month". "m"
是一个文字字符串,表示参数为“ month”。
dt = DateAdd("m", i, dt)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.