我正在尝试使用VB向当前日期字段添加天数。我正在使用两张不同的纸张来了解详情。以下是我的代码 -
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
我没有得到理想的价值。能不能让我知道我哪里出错了。
提前致谢
答案 0 :(得分:0)
以下是我正在使用的当前代码,我做了一些细微的更改,但除了删除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