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?
 
TracyConnect With a Mentor VBA 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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.