I am trying to add no of days to current date field using 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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.