Date function in vba code

I have a worksheet with columns Year, Month, Day and Hour. I need to combine it to date.
On the workshhet,  I used the formula date(A1,B1,C1) + time(D1,0,0) and it worked fine. I would like to know how to do this in a macro.
I used the attached code, but it returns the value as 1/0/00 0:00. Any ideas ?
Thanks !

sub datemacro()
Dim i As Integer
Dim intLastRow As Integer
intLastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To intLastRow
Range("L" & i) = "=date(A&i,B&i,C&i)+time(D&i,0,0)"
Next i
Range("A1").Select
End Sub

Open in new window

MPI_ITAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TracyVBA DeveloperCommented:
Change this:
Range("L" & i) = "=date(A&i,B&i,C&i)+time(D&i,0,0)"

to this:
Range("L" & i) = "=date(A" & i & ", B" & i & " ,C" & i ")+time(D" & i & ",0,0)"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MPI_ITAuthor Commented:
Hi broomee9,
It showed syntax error first, small typo, fixed it and worked great !
Just pritning the formula,  for future reference to others.
Range("L" & i) = "=date(A" & i & ", B" & i & " ,C" & i  &")+time(D" & i & ",0,0)"
Thanks for you quick help !
0
MPI_ITAuthor Commented:
Thanks for the help !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.