hotseetotsee
New Member
- Joined
- Dec 20, 2016
- Messages
- 7
I am trying to populate an End Date for my table based on the Start Date and the Duration stated by the user.
My table are as shown as below:
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]Task[/TD]
[TD]Start Date[/TD]
[TD]Duration
(day(s))[/TD]
[TD]End Date[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]5/12/2016[/TD]
[TD]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]7/12/2016[/TD]
[TD]7[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I have tried to run a VBA code as follows but it returned as Run-Time Error '1004': Application defined or object-defined error
I am new to VBA and I really appreciate if you could help me with this. Thanks.
My table are as shown as below:
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]Task[/TD]
[TD]Start Date[/TD]
[TD]Duration
(day(s))[/TD]
[TD]End Date[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]5/12/2016[/TD]
[TD]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]7/12/2016[/TD]
[TD]7[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I have tried to run a VBA code as follows but it returned as Run-Time Error '1004': Application defined or object-defined error
Code:
Sub PlannedEndDate()
Dim userInputDate As Date
Dim duration As Double
Dim endDate As Date
userInputDate = Range("C6" & Rows.Count).End(xlUp).Row
duration = Range("D6" & Rows.Count).End(xlUp).Row
endDate = Range("E6" & Rows.Count).End(xlUp).Row
If duration = "" Then
endDate = DateAdd("d", duration, userInputDate)
Else
endDate = userInputDate
End If
End Sub
I am new to VBA and I really appreciate if you could help me with this. Thanks.