[英]DateAdd function in excel-vba
I am trying to add no of days to current date field using VB. 我正在尝试使用VB向当前日期字段添加天数。 I am using two different sheets for details. 我正在使用两个不同的工作表以获取详细信息。 Below is my code- 以下是我的代码-
Dim data3 As Variant
Dim data5 As Variant
Dim data6 As Date
Dim duedate As Date
for i = 1 to 10
data3 = Sheets("Sheet1").Cells(i, "A").Value
data5 = Sheets("Sheet1").Cells(i, "C").Value
data6 = CDate(Sheets("Sheet2").Cells(i, "C").Value)
If data3 = "Value1" And (data5 = "Value2" Or data5 = "Value3") Then
duedate = DateAdd("d", 5, data6)
Sheets("Sheet1").Cells(i, "D").Value = duedate
Else
'Do nothing
End If
Next i
I am not getting desired value. 我没有得到期望的价值。 Could you please let me know where I am going wrong. 您能否让我知道我要去哪里错了。
Thanks in advance 提前致谢
Here is the current code that I am using, I made a few slight changes, but aren't really of any significance to your code above, besides getting rid of the DateAdd
part. 这是我正在使用的当前代码,我做了一些细微的更改,但是除了摆脱了DateAdd
部分之外,对您上面的代码没有任何意义。
Sub test()
Dim data3 As Variant
Dim data5 As Variant
Dim data6 As Date
Dim duedate As Date
For i = 1 To 10
data3 = Sheets(1).Cells(i, "A").Value
data5 = Sheets(1).Cells(i, "C").Value
data6 = CDate(Sheets(2).Cells(i, "C").Value)
If data3 = "Value1" And (data5 = "Value2" Or data5 = "Value3") Then
duedate = data6 + 5
Sheets(1).Cells(i, "D").Value = duedate
End If
Next i
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.